int main()
{
int num1, // The first random number
num2, // The second random number
choice, // The user's choice of problem
studentAnswer, // The student's answer
correctAnswer; // The correct answer
// Seed the random number generator.
srand(time(0));
do
{ // Display the menu and get a choice.
cout << "\tMath Tutor Menu\n";
cout << "------------------------------\n";
cout << "1. Addition problem\n";
cout << "2. Subtraction problem\n";
cout << "3. Multiplication problem\n";
cout << "4. Division problem\n";
cout << "5. Quit this program\n";
cout << "------------------------------\n";
cout << "Enter your choice (1-5): ";
cin >> choice;
// Validate the choice.
while (choice < 1 || choice > 5)
{
cout << "The valid choices are 1, 2, 3, "
<< "4, and 5. Please choose: ";
cin >> choice;
}
// Produce a problem.
switch (choice)
{
case 1: // Addition problem
// Generate two random numbers in
// the range 1 - 500.
num1 = 1 + rand() % 500;
num2 = 1 + rand() % 500;
// Calculate the correct answer.
correctAnswer = num1 + num2;
case 3: // Multiplication problem
// Generate two random numbers. The first in
// the range 1 - 100, the second in the
// range 1 - 9.
num1 = 1 + rand() % 100;
num2 = 1 + rand() % 9;
// Calculate the correct answer.
correctAnswer = num1 * num2;
case 5: // The user chose to quit the program.
cout << "Thank you for using Math Tutor.\n\n";
break;
}
// If student selected a problem, get and evaluate the answer.
if (choice >= 1 && choice <= 4)
{
cin >> studentAnswer;
if (studentAnswer == correctAnswer)
cout << "\n\nCongratulations! That's right.\n\n";
else
cout << "\n\nSorry, the correct answer is " << correctAnswer
<< ".\n\n";
}
} while (choice != 5); // Loop again if student did not choose to quit.
return 0;
}
The assignment is to modify it so these things are included:
Here is the instruction for my assignment
1. Gives instructions
2. Displays previous user’s name and score from file
3. Prompts for the current user’s name
4. Provides a menu of math choices (e.g., +. -, *, /), plus exit
5. Asks users how many questions they want to answer
6. Asks user for highest number to use
7. Displays appropriate math questions with random numbers
8. Keeps track of right and wrong answers
9. Provide at least 10 randomly chosen correct and incorrect answers for feedback
10. Gives feedback on how many questions answered and percent right for that group
11. Returns to menu for possible additional problems
12. When exit chosen shows grand total statistics – correct, attempted, and percent right
13. Writes name and results to file
14. When running again displays name and results of last person to use the program
15. Break program into appropriate functions
16. Write and use data validation functions in a private library of your creation that includes generic functions for getString, getInt, and getFloat.