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