Question 1. Your task is to write a program to repeatedly generate random multip
ID: 3864652 • Letter: Q
Question
Question 1. Your task is to write a program to repeatedly generate random multiplications to quiz the user, and keep score. Generate the two multiplicands (e.g. 6 and 7) and compute the correct answer (42). Then 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 fraction (e.g. 5/8 correct) and a percentage, displayed to the nearest percent (e.g. 63%). Continue generating questions as long as the user indicates he/she would like to keep playing. Constraint: you must include functions in your program. Include at least these 4 functions, fitting the supplied prototypes: 1. A function called NewRandomNumber() that receives an integer n (e.g. 10), and returns a new random number between 2 and n. We don't want to make questions like 1x3 or 0x8 because these are too easy. int NewRandomNumber(int n); Your function should make use of rand() (part of the cstdlib library) . rand() generates a pseudo-random integer between 1 and 32767. use % and + to convert this integer to an integer between 2 and n. 2. A function MakeQuestion() to create the question to ask the user. This function should call NewRandomNumber() twice to make two new random numbers; it should figure out what the answer should be, and then return the two numbers and the answer. MakeQuestion()needs to know about n so it can tell NewRandomNumber() what kind of numbers to make. Because this function needs to return 3 values, it should use reference parameters. void MakeQuestion(int n, int& a, int& b, int& atimesb); 3. A function UserAnswerIsCorrect() that uses the two operands and the correct answer which were generated in MakeQuestion() and presents the question to the user via cout. It then receives the user’s answer via cin and compares it against the correct answer. If the user’s answer is correct, it returns True. Otherwise, it returns False. bool UserAnswerIsCorrect(int a, int b, int correctAnswer); 4. A function PrintScore() that receives the total number of questions the user has answered correctly, as well as the total number of questions, and computes and displays the user’s score as a fraction and as a percentage. void PrintScore(int numCorrect, int numAsked); At the beginning of the program, the user should be able to choose their difficulty by entering a number. For example, if the user enters "4", the computer should only generate questions up to 4 times 4. If the user enters "12", the program should generate questions up to 12 times 12. Your program should also generate a log file of important data, such as the generated question, the user's response, and the cumulative score. This log should be a comprehensive record of the program run, but should not be a duplication of every user interaction. Further, you mustformat this log file nicely. For example: QUIZ PROGRAM LOG FILE User name: John Smith Difficulty: 8 Question Response Cumul. Score ============== ======== ========--====== 3 * 5 = 15 15 1/1 (100%) 8 * 2 = 16 16 2/2 (100%) 6 * 9 = 54 45 2/3 (66%) END OF SESSION Make sure to fully test your program, and show your testing in your log file. Justify your choice of test cases in your comments. BONUS: Research and make use of a random number seed, so that the random numbers are different every time the program is run.
Explanation / Answer
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<stdlib.h>
int numgen();
void int mul();
int main()
{
int n1,n2,ans,count=1,q,userans;
char name;
srand(time(NULL));
printf("Enter your name");
scanf("%s",&name);
printf("how many times do you take me to quize");
scanf("%d",&q);
while(c<=q)
{
printf(how much is %d multiplied by &d",numgen(n1),numgen(n2));
scanf("&d",&userans);
ans=n1*n2;
while(userans!=ans)
printf("Sorry wrong answer and try again");
scanf("%d",&userans);
}
if(userans==ans)
{
printf("correct answer");
c++;
int numgen(int fn);
{
fn=1+(rand()%9);
return fn;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.