Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main()
- {
- int num1,
- num2,
- choice,
- studentAnswer,
- correctAnswer;
- srand(time(0));
- do
- {
- cout << "n-----------------------------------n"
- << " Math Tutorn"
- << " M E N Un"
- << "-----------------------------------n";
- cout << "1. Addition problemn";
- cout << "2. Subtraction problemn";
- cout << "3. Multiplication problemn";
- cout << "4. Division problemn";
- cout << "5. Quit this programn";
- cout << "------------------------------n";
- cout << "Enter your choice (1-5): ";
- cin >> choice;
- while (choice < 1 || choice > 5)
- {
- cout << "The valid choices are 1, 2, 3, "
- << "4, and 5. Please choose: ";
- cin >> choice;
- }
- switch (choice)
- {
- case 1:
- num1 = 1 + rand() % 500;
- num2 = 1 + rand() % 500;
- correctAnswer = num1 + num2;
- cout << "nn";
- cout << " " << setw(4) << num1 << endl;
- cout << " +" << setw(4) << num2 << endl;
- cout << " " << "----" << endl;
- cout << " ";
- break;
- case 2:
- num1 = 1 + rand() % 999;
- num2 = 1 + rand() % 999;
- while (num2 > num1)
- num2 = 1 + rand() % 999;
- correctAnswer = num1 - num2;
- cout << "nn";
- cout << " " << setw(4) << num1 << endl;
- cout << " -" << setw(4) << num2 << endl;
- cout << " " << "----" << endl;
- cout << " ";
- break;
- case 3:
- num1 = 1 + rand() % 100;
- num2 = 1 + rand() % 9;
- correctAnswer = num1 * num2;
- cout << "nn";
- cout << " " << setw(4) << num1 << endl;
- cout << " *" << setw(4) << num2 << endl;
- cout << " " << "----" << endl;
- cout << " ";
- break;
- case 4:
- num2 = 1 + rand() % 9;
- num1 = num2 * (rand() % 50 + 1);
- correctAnswer = num1 / num2;
- cout << "nn";
- cout << " " << num1 << " / " << num2 << " = ";
- break;
- case 5:
- cout << "Thank you for using Math Tutor.nn";
- break;
- }
- if (choice >= 1 && choice <= 4)
- {
- cin >> studentAnswer;
- if (studentAnswer == correctAnswer)
- cout << "nnCongratulations! That's right.nn";
- else
- cout << "nnSorry, the correct answer is " << correctAnswer
- << ".nn";
- }
- } while (choice != 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement