IDNLearn.com provides a seamless experience for finding accurate answers. Discover detailed and accurate answers to your questions from our knowledgeable and dedicated community members.
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 :
We value your participation in this forum. Keep exploring, asking questions, and sharing your insights with the community. Together, we can find the best solutions. For clear and precise answers, choose IDNLearn.com. Thanks for stopping by, and come back soon for more valuable insights.