Question: How to fix the division case. As you notice when comparing two floating point numbers, it gives the wrong result as the answer always rounds
How to fix the division case. As you notice when comparing two floating point numbers, it gives the wrong result as the answer always rounds up to integers.
(HELP Me with fixing my code, only the divsion part, the rest is fine, thanks)

using namespace std;
int main()
{
int choice = 0,num1, num2, ans, user_ans;
while (choice != 5)
{
cout
cout
cout
cout
cout
cout
cout
cout
cin >> choice ;
while ((choice > 5) or ( choice
{
cout
cout
cin >> choice;
}
if (choice == 5)
cout
else if ( choice == 1)
{
srand(time(NULL));
num1 = rand() %999, num2 = rand() % 999;
cout
cout
cout
cout
cin >> user_ans ;
ans = num1 + num2;
if ( user_ans == ans)
cout
if ( user_ans != ans)
cout
}
else if ( choice == 2)
{
srand(time(NULL));
num1 = rand() %999, num2 = rand() % 999;
cout
cout
cout
cout
cin >> user_ans ;
ans = num1 - num2;
if ( user_ans == ans)
cout
if ( user_ans != ans)
cout
}
else if ( choice == 3)
{
srand(time(NULL));
num1 = rand() %999, num2 = rand() % 999;
cout
cout
cout
cout
cin >> user_ans ;
ans = num1 * num2;
if ( user_ans == ans)
cout
if ( user_ans != ans)
cout
}
else if (choice == 4)
{
srand(time(NULL));
num1 = rand() %999, num2 = rand() % 999;
cout
cout
cout
cout
cin >> user_ans ;
ans = num1 / num2;
if ( user_ans == ans)
cout
if ( user_ans != ans)
cout
}
}
return 0;
}
Math Tutor Menu 1: addition 2: subtraction 3: multiplication 4: division 5: quit Enter your choice (1~5):4 Enter the answer 274 23 0.00 Your answer is wrong, the correct answer is: 1 Process returned 0 (0x0 execution time 2.274 s Press ENTER to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
