Question
Generate 2 random integers(one within 50 and the next one within 100) and ask the user to input the correct added value of 2 integers.
Generate 2 random integers(one within 50 and the next one within 100) and ask the user to input the correct added value of 2 integers. Try to generate 10 questions randomly. If the user answered correctly, keep a count of correct answers. If the answer is wrong display the correct answer with a comment, Your answer is wrong. The correct answer is .. Finally display the count of correct answers.
Sample outputs:
What is 30 + 79? 109
What is 4 + 81? 85
What is 23 + 50? 73
What is 48 + 39? 34
Wrong answer.
Your correct answer is 87
What is 25 + 54? 79
What is 6 + 16? 22
What is 29 + 47? 65
Wrong answer.
Your correct answer is 76
What is 41 + 67? 34
Wrong answer.
Your correct answer is 108
What is 10 + 63? 73
What is 42 + 86? 128
Your have answered 7 questions correctly.
Sample code:
#include
#include
#include
int main ()
{
srand(time(0));
int number1 = rand() % 51;
int number2 = rand() % 101;
int answer;
printf("What is %d + %d?", number1, number2);
scanf("%d", &answer);
while (answer != number1 + number2)
{
printf("Wrong answer. Try again. What is %d + %d ? ", number1, number2);
}
puts("you got it!");
}
In C code (not c++ or java)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started