Question

This week we looked at an example math program that would display the answer to a...

This week we looked at an example math program that would display the answer to a random math problem. Enhance this assignment to prompt the user to enter the solution to the displayed problem. After the user has entered their answer, the program should display a message indicating if the answer is correct or incorrect. If the answer is incorrect, it should display the correct answer. The division section should use Real data types instead of Integer data types. Keep track of how many correct/incorrect answers the user makes during the program and when they choose to exit, the program should display the percentage they got correct (# of correct / total # attempted).

HINT:
Keep in mind you will need to add 1 or more additional parameters to the addition, subtraction, multiplication, and division methods to support the ability to track the total attempted and total correct. Also, be aware with the way Real numbers are stored in memory, it will be nearly impossible for you to get a division problem correct. You don't need to worry about adjusting for this in your program, I just want to make you aware of this in case you run into this issue while testing your program. Let me know if you have questions or would like to discuss this further.

Example Output:
1) Addition
2) Subtraction
3) Multiplication
4) Division
5) Exit
Enter your selection:
1[Enter]
12 + 34 =
45 [Enter]
I’m sorry, the correct answer was 46

1) Addition
2) Subtraction
3) Multiplication
4) Division
5) Exit
Enter your selection:
2[Enter]
45 – 2 =
43[Enter]
Yes, that is the correct answer!

1) Addition
2) Subtraction
3) Multiplication
4) Division
5) Exit
Enter your selection:
5 [Enter]
Thanks for playing. You answered 1 out of 2 questions correct for a score of 50%

IMPORTANT:

PROGRAM MUST BE RAPTOR IN INTERMEDIATE MODE.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
#include<stdlib.h>
#include<time.h>

using namespace std;

int main(){

int ch;
double a,b,ans;
srand(time(NULL));
while(1){

     cout << "1.Addition\n";
     cout << "2.Subtraction\n";
     cout << "3.Multipliction\n";
     cout << "4.Divison\n";
     cout << "5.Exit\n\n";
     cout << "Enter your choice :";

     cin >> ch;
     a = rand()%100+1;
     b = rand()%100+1;
     if (ch == 5)
        break;
     if (ch == 1){
        cout << a << " " << "+" << " " <<b << " " << "= "<< endl;
        cin >> ans;
        if (ans == a+b)
           cout << "Correct\n";
        else
           cout << "I am sorry the correct answer is " << a + b << endl;
     }
     if (ch == 2){
        cout << a << " " << "-" << " " <<b << " " << "= "<< endl;
        cin >> ans;
        if (ans == a-b)
           cout << "Correct\n";
        else
           cout << "I am sorry the correct answer is " << a - b << endl;
     }
     if (ch == 3){
        cout << a << " " << "*" << " " <<b << " " << "= "<< endl;
        cin >> ans;
        if (ans == a*b)
           cout << "Correct\n";
        else
           cout << "I am sorry the correct answer is " << a * b << endl;
     }
     if (ch == 4){
        cout << a << " " << "/" << " " <<b << " " << "= "<< endl;
        cin >> ans;
        if (ans == a/b)
           cout << "Correct\n";
        else
           cout << "I am sorry the correct answer is " << a / b << endl;
     }
}
return 0;
}

Add a comment
Know the answer?
Add Answer to:
This week we looked at an example math program that would display the answer to a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the...

    (For Python program)   Write a program that fulfills the functionalities of a mathematical quiz with the four basic arithmetic operations, i.e., addition, subtraction, multiplication and integer division. A sample partial output of the math quiz program is shown below. The user can select the type of math operations that he/she would like to proceed with. Once a choice (i.e., menu option index) is entered, the program generates a question and asks the user for an answer. A sample partial output...

  • Write a MIPS math quiz program in MARS. The program should start with a friendly user...

    Write a MIPS math quiz program in MARS. The program should start with a friendly user greeting. From there, it should generate a random arithmetic problem. Your program will need to generate three random things: the first and second operand and the operator to use. Your program should generate random positive integers no greater than 20 for the operands. The possible operators are +, -, * and / (division). The user should be prompted for an answer to the problem....

  • Write a Python Program that displays repeatedly a menu as shown in the sample run below....

    Write a Python Program that displays repeatedly a menu as shown in the sample run below. The user will enter 1, 2, 3, 4 or 5 for choosing addition, substation, multiplication, division or exit respectively. Then the user will be asked to enter the two numbers and the result for the operation selected will be displayed. After an operation is finished and output is displayed the menu is redisplayed, you may choose another operation or enter 5 to exit the...

  • Math Problem Generator Your job will be to write a C++ program to teach math to...

    Math Problem Generator Your job will be to write a C++ program to teach math to school children. Your program will accomplish this by showing sets of math problems to the user and allowing them to enter an answer. The program should tell the user if they are correct and should continue providing additional questions. The program will keep track of correct and incorrect answers. The questions should use random numbers and should be simple enough math problems that someone...

  • Read description carefully. Needs to catch exceptions and still be able to keep the program going...

    Read description carefully. Needs to catch exceptions and still be able to keep the program going on past the error. Program should allow user to keep going until he or she quits Math tutor) Write a program that displays a menu as shown in the sample run. You can enter 1, 2. 3, or 4 for choosing an addition. subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter...

  • Instructions Basically, you will modify the mathq program to make it satisfy a different set of...

    Instructions Basically, you will modify the mathq program to make it satisfy a different set of requirements, and fix what is not working in it. Specifically, imagine that the client for whom we created the mathq program for would now like some changes. To be exact: Part 1: They want it to provide addition and subtraction problems as well as multiplication and division. They still want the choice to be random, as before, but now the problem is randomly multiplication,...

  • RAPTOR PROGRAMMING Write a program which will receive two integer values as input. Then prompt the...

    RAPTOR PROGRAMMING Write a program which will receive two integer values as input. Then prompt the user to choose one of the following operations and produce an output with the selected operation. 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulo Division Example output with response: Please enter an input: 2 Please enter another input: 3 Please choose from the follow: 1. Addition 2. Subtraction 3. Multiplication 4. Division 5. Modulo Division Output: 2 % 3 is 2.

  • I am learning programming in JAVA. Please help me with this programming assignment. Your lab assignment...

    I am learning programming in JAVA. Please help me with this programming assignment. Your lab assignment this week is to build a little math program to help kids practice their addition and subtraction. You will create a menu and have the kid select what kind of math problem they want to solve. Once the kid selects what kind of problem. Randomly generate two numbers, display the problem and allow the kid to enter the answer. If the answer is correct....

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • need help writing a translator program in java. the program needs to be able to preform...

    need help writing a translator program in java. the program needs to be able to preform basic math calculations of addition,subtraction,division,multiplication. I also need to create my own syntax for them so for example if a user would be prompted to enter the syntax for addition they could type in ":/a 2 3" and the output would be 5 subtraction "//s 5 3 and the ouput would be 2, division "!!d 6 3" the output would be 2, multiplication "**m...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT