write a c++ program that repeatedly generate random multiplications to quiz the
ID: 3644977 • Letter: W
Question
write a c++ program that repeatedly generate random multiplications to quiz the user. Randomly generate the operands of a question, and compute the correct answer. Ask the user for his/her answer, and compare it to the correct answer. If the user gets it right, increment the total score. Display the score as a percentage: the total questions the user has gotten right out of the total questions he/she has been asked. Continue generating questions as long as the user indicates he/she would like to keep playing. include, 1. A function called GetRandomNumber that generates a random number between 1 and10
2. A function called GenerateQuestion that creates and sends back to main two randomly
generated operands, and the correct answer to the question
3. A function called AskUser that takes the two operands of the equation and the correct
answer. It prints the question for the user, and inputs the user
Explanation / Answer
Please rate...
The above program doesnot have the correct functions according to the question....
Here, take this solution...:)..
program:
======================================================================
#include<iostream>
#include<stdlib.h>
using namespace std;
int genrand()
{
int isecret;
isecret = 1+rand() % 10 ;
while(isecret==0)isecret = 1+rand() % 10 ;
return isecret;
}
void generateQuestion(int &a,int &b,int &c)
{
a=genrand();
b=genrand();
c=a*b;
}
int AskUser()
{
int a,b,c,d;
generateQuestion(a,b,c);
cout<<a<<" * "<<b<<" = ";
cin>>d;
if(d==c){cout<<" Correct";return 1;}
else {cout<<" Nope!";return 0;}
}
void PrintScore(int q,int a)
{
cout<<" You answered "<<a<<"/"<<q<<" correctly";
cout<<" Your score is "<<(double)a/q;
}
int main()
{
char c='y';
int a=0,b=0;
while(c=='y' || c=='Y')
{
if(AskUser()==1)a++;
b++;
PrintScore(b,a);
cout<<" Do you want to continue? (y/n): ";
cin>>c;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.