At Westonci.ca, we connect you with the best answers from a community of experienced and knowledgeable individuals. Join our platform to connect with experts ready to provide detailed answers to your questions in various areas. Our platform provides a seamless experience for finding reliable answers from a network of experienced professionals.

Write a while loop that reads integers from input and calculates finalVal as follows:

If the input is divisible by 3, the program outputs "hit" and increases finalVal by 1.
If the input is not divisible by 3, the program outputs "miss" and doesn't update finalVal.
The loop iterates until a negative integer is read.

Ex: If the input is 6 9 4 -2, then the output is:

hit
hit
miss
Final value is 2

Note: x % 3 == 0 returns true if x is divisible by 3.

Code:

#include
using namespace std;

int main() {
int in;
int finalVal;

finalVal = 0;
cin >> in;

/* Your code goes here */

cout << "Final value is " << finalVal << endl;

return 0;
}


Sagot :

Thank you for trusting us with your questions. We're here to help you find accurate answers quickly and efficiently. Thank you for your visit. We're committed to providing you with the best information available. Return anytime for more. Westonci.ca is your go-to source for reliable answers. Return soon for more expert insights.