Problem: Write a C++ program that uses a single DO…WHILE loop structure to create a
math tutor for young students
Display a menu offering the user the option of performing addition, subtraction, multiplication,
or division (use a “switch”). Create separate functions for addition, subtraction,
multiplication, and division. The final selection on the menu should allow the user to exit the
program. The menu is to be displayed again after the user has finished each problem. Use the
“rand” function to display two random numbers to be used in each problem (see NOTE below).
The program should then pause while the student works on the problem and enters his/her
answer. When the student enters his/her answer and presses the “Enter” key, the program will
display the correct solution. If the answer is correct, the program will display a message of
congratulations. If the answer is incorrect, the program will display a message along with the
correct answer.
When the program ends, display a message “thanking” the user for using the Math Tutor
program. Use appropriate output formatting features to make your output line up as in the
sample output below.
NOTE: For addition, generate random numbers in the range 1 – 500.
For subtraction generate random numbers in the range 1 – 999
(the second number must be less than the first number).
For multiplication generate random numbers in the range 1 – 100 for the first
number and generate random numbers in the range 1 – 9 for the multiplier.
For division generate random numbers in the range 1 – 9 for the divisor; generate
random numbers in the range generate random numbers in the range 1 – 50 for
the numerator and then multiply the random number by the divisor so that the
result is always a whole (integer) number.
Information about the rand() function can be found on pages 129-130 in the text.
The shorthand (or abbreviated) version is: srand(time(0));
No, I can not do it for you. Show me what you have so far and I will proceed to explain how to finish it. You might want to use a random seed to get your numbers.
I did something like this not too long ago (I am also learning). You should really try and figure it out on your own because if you can't then you didn't try hard enough. As a tip heres one way you could do multiplication.
void multiplicationFunc(string test2)
{
srand(time(0));
int answer;
int n1 = rand() % 100 + 1;
int n2 = rand() % 9 + 1;
cout << "-------------------\n"
<< "-------------------\n"
<< "| What is " << n1 << " X " << n2 << " ? |\n"
<< "-------------------\n"
<< "-------------------\n";
answer = validateNumber(); //If you don't have to validate then cin >> answer;
if (answer == n1 * n2)
{
system("cls");
isCorrect(test2); //A function that assigns points if it is correct.
cout << " ****** Correct! *******\n";
}
else
{
system("cls");
isWrong(test2); //A function that assigns points if it is wrong.
cout << " ****** Wrong! ******\n";
}
}
You are literally asking someone else to do it for you though, which would defeat the whole purpose of you learning C++ anyways.
P.S The reason i have a "isWrong" and "isCorrect" function was because for my project I had to assign or take away points from the user and that's one way I went about it.
//This program will be used to help tutor math students
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
#define IDLINE "-CS1336-Bonus lab\n"
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
//Display the ID line
cout << IDLINE << endl ;
// Seed the random number generator.
srand(time(0));
// 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;
}