Using a priming read, allow the user to enter a Y or y into a char variable call
ID: 3624755 • Letter: U
Question
Using a priming read, allow the user to enter a Y or y into a char variable called continueYN to the question,"Do you want to continue?" If they do, then do while toUpper(continueYN) == 'Y'Use the random number generator to generate two numbers between 1 and 20.
Display these numbers to the user and then prompt them to give you the sum.
If the sum is equal to the sum of the two numbers, tell them they got it correct and add 1 to a correct counter, else add 1 to an incorrect counter.
Also, add 1 to an accumulator.
At the end of the loop ask the person if they want to continue. If Y then continue in the loop and ask them to add two more randomly generated numbers.
Keep doing this until the person enters something other than a Y.
Once out of the loop, display the number the person got right, the number they got wrong and the total times they went through the loop.
Explanation / Answer
please rate -thanks
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{char continueYN;
srand(time(0));
int n1,n2,sum,right=0,wrong=0,acc=0;
do
{n1=rand()%20+1;
n2=rand()%20+1;
cout<<"How much is "<<n1<<" + "<<n2<<"? ";
cin>>sum;
if(sum==n1+n2)
right++;
else
wrong++;
acc++;
cout<<"Do you want to continue(Y/N)? ";
cin>>continueYN;
}while(toupper(continueYN) == 'Y');
cout<<"SUMMARY ";
cout<<"Number right: "<<right<<endl;
cout<<"Number wrong: "<<wrong<<endl;
cout<<"Times through the loop: "<<acc<<endl;
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.