So I'm writing code for a math tutor program that has a selection menu and the user can addition, subtraction, multiplication, and division. I've gotten all but the division section to function the way i need them to. My teacher has said that I can never result in a negative or fractional answer, even for subtractions and
divisions, and that the best way to try and do this for the division part is to generate two random numbers in the 1-12 range, multiply them together,
and set the first number to that value. Here's the code I have for the division portion so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
cout << "You have chosen Division, please answer the following questions: \n";
do
{
//Generating the Random Numbers
num1 = 1 + rand() % 12;
num2 = 1 + rand() % 12;
cout << "Question " << (divQuestion += 1) << endl;
cout << divNum << " / " << num1 << " = ";
cin >> UserAnswer;
if (UserAnswer == divNum / num1)
{
cout << "Correct \n" << endl;
userDivScore += 1;
cout << "Your Score is: " << userDivScore << "/10 \n";
}
else
{
cout << "Incorrect \n" << endl;
cout << "Your score is : " << userDivScore << "/10 \n";
}
} while (divQuestion < 10);
|
I wish I could do this in functions, which would probably solve my problem, but my teacher has said that it has to be in a switch form. I've tried setting the divNum variable to equal num1 * num2, and I've also tried setting it within my division code (divNum == num1 * num2) but every time I run the program divNum is always 0. I've searched the web and searched this site, and while I've found similar programs to what I'm making, I haven't seen a way to fix my problem. Any help is appreciated.