Welcome to Westonci.ca, the place where your questions are answered by a community of knowledgeable contributors. Get immediate and reliable solutions to your questions from a community of experienced experts on our Q&A platform. Get precise and detailed answers to your questions from a knowledgeable community of experts on our Q&A platform.

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;
}