You are going to create a simple calculator.

  1. The program should call a function to display a menu of three options:
    a. 1 – Integer Math
    b. 2 – Double Math
    c. 3 – Exit Program
  2. The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option selected.
  3. If the user selects 1 or 2, the program should allow the user to enter in any two numbers.
    a. The program must create 5 functions called add, subtract, multiply, divide and mod. These functions must take two integers as arguments and return an integer to the calling function. Each function performs the appropriate mathematical task.
    b. The program must create 4 functions called add, subtract, multiply and divide. These functions must take two doubles as pass by value parameters and one double as a pass by reference variables. The function does the calculation and sets the reference variable to the calculated value; this is how the value is returned to the calling function. Each function performs the appropriate mathematical task.
    c. The program must create two functions called display.
    i. The first display function takes the five integer values calculated and displays them
    ii. The second display function takes the four double values calculated and display them to two decimal places
  4. If the user select 3, the program should call a function to display a goodbye message. EXTRA CREDIT: If the user select 3, the program should call a function to ask the user if they want to exit the program. The only valid responses are Y, y, N and n. The program must test that the user enters in a valid response. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return a Boolean back to the calling function telling the calling function to allow for a new entry to end the program.
  5. The program should only end if the user selects 3 from the menu (or the combination of 3 and y or Y for the EXTRA CREDIT). There is no other way to end the program.
  6. Print some goodbye message.
  7. Notes:
    a. The program must declare all of the functions using prototypes.
    b. All integer functions must return a value. The main program should always contain a variable to catch that return value. All of the functions that use pass by reference should have a data return type of void.

Sample Solution

This question has been answered.

Get Answer