(Repeat additions) Listing, SubtractionQuizLoop.cpp, generates five random subtraction questions. Revise the program to generate ten random addition questions for two integers between 1 and 15. Display the correct count and test time.
Listing
1 #include
2 #include // Needed for time function3 #include // Needed for the srand and rand functions4 using namespace std;56 int main()7 {8 int correctCount = 0; // Count the number of correct answers9 int count = 0; // Count the number of questions10 long startTime = time(0);11 const int NUMBER_OF_QUESTIONS = 5;1213 srand(time(0)); // Set a random seed1415 while (count < NUMBER_OF_QUESTIONS)16 {17 // 1. Generate two random single-digit integers18 int number1 = rand() % 10;19 int number2 = rand() % 10;2021 // 2. If number1 < number2, swap number1 with number222 if (number1 < number2)23 {24 int temp = number1;25 number1 = number2;26 number2 = temp;27 }2829 // 3. Prompt the student to answer "what is number1 − number2 ?"30 cout << "What is " << number1 << " − " << number2 << "? "; display a question31 int answer;32 cin >> answer;3334 // 4. Grade the answer and display the result35 if (number1 − number2 == answer) grade an answer36 {37 cout << "You are correct !\n";38 correctCount++ ; increase correct count39 }40 else 41 cout << "Your answer is wrong.\n" << number1 << " − " <<42 number2 << " should be " << (number1 − number2) << end⌉;4344 // Increase the count45 count++ ; increase control variable46 }4748 long endTime = time(0); get end time49 long testTime = endTime − startTime; test time5051 cout << "Correct count is " << correctCount << "\nTest time is " display result52 << testTime << "seconds \n";5354 return 0 ;55 }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.