Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- using namespace std;
- int main()
- {
- string name;
- int selection;
- int x;
- int y;
- int correctAnswer;
- int userAnswer;
- int count = 1;
- int totalCorrectAnswers = 0;
- int numberOfAttempts = 0;
- cout << "Please enter your first name. ";
- cin >> name;
- cout << "\nHello, " << name << ". What sort of math problems would you like to work on?\n(Type the number, or type '4' to quit the program.)\n" << endl;
- cout << "1) Addition"
- << "\n2) Subtraction"
- << "\n3) Multiplication"
- << "\n4) Quit\n" << endl;
- cin >> selection;
- if (selection == 1)
- {
- cout << "\nAll right! Let's do some addition." << endl;
- cout << "When you've gotten 10 correct answers, you'll receive a grade out of 100.\n" << endl;
- while (totalCorrectAnswers < 10)
- {
- srand(time(NULL));
- x = rand() % 20;
- y = rand() % 20;
- correctAnswer = x + y;
- cout << "Question " << count << ": " << x << " + " << y << " = ";
- cin >> userAnswer;
- count++;
- numberOfAttempts++;
- if (userAnswer == correctAnswer)
- {
- cout << "Correct!\n";
- ++totalCorrectAnswers;
- }
- else
- {
- cout << "Incorrect.\n";
- }
- }
- cout << "Great job! Your total grade is " << ((totalCorrectAnswers / numberOfAttempts) * 100) << "." << endl;
- }
- else if (selection == 2)
- {
- cout << "All right! Let's do some subtraction." << endl;
- cout << "We're going to give you some basic subtraction problems, and when you've gotten 10 correct, you'll receive a grade out of 100." << endl;
- while (totalCorrectAnswers < 10)
- {
- }
- }
- else if (selection == 3)
- {
- cout << "All right! Let's do some multiplication." << endl;
- cout << "We're going to give you some basic multiplication problems, and when you've gotten 10 correct, you'll receive a grade out of 100." << endl;
- while (totalCorrectAnswers < 10)
- {
- }
- }
- else if (selection == 4)
- {
- cout << "Goodbye." << endl;
- }
- else
- {
- cout << "Error! Please enter 1, 2, 3, or 4.\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement