At Westonci.ca, we connect you with the best answers from a community of experienced and knowledgeable individuals. Join our Q&A platform to get precise answers from experts in diverse fields and enhance your understanding. Discover detailed answers to your questions from a wide network of experts on our comprehensive 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;
}