$24
Summary: Write a console program (character based) to do simple calculation (addition, subtraction, multiplication and division) of two numbers using your understanding of control flow, input validations and error conditions in C.
Description: You need to write a program that when run will display a menu. The menu gives five choices of operation: addition, subtraction, multiplication, division and a last choice to exit the program. It then gives a prompt and waits for the user to make a choice of calculation they want to do. Once user selects the operation it will check for valid menu choices (and give an appropriate message if a wrong choice was selected) and then prompts to enter two numbers separated by a space. If the user entered valid numbers it will do the operation desired and then displays the result. If user input is not valid displays an error message and asks for the correct input. At the end of the result, it gives aprompt “Press enter key to continue ….”. Once enter key is pressed,it displays the menu again. Program repeats until user selects a choice to exit.
Sample Run of the program:
Welcome to <John Doe’s> Handy Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
What would you like to do? 0
That is not a valid choice, please re-‐enter: k sdfs sfs
That is not a valid choice, please re-‐enter: 9
That is not a valid choice, please re-‐enter: 3
Please enter two numbers to multiply, separated by a space: 24.0 4.0
Result of multiplying 24.00 and 4.00 is 96.00.
Press enter key to continue ….
Welcome to <John Doe’>s Handy Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
What would you like to do? 4
Please enter two numbers to divide separated by a space:2.0 0
You can’t divide by zero, please re-‐enter both numbers: asasfs asdfasfas f; sf af sfs
Error reading your numbers, please re-‐enter both numbers: 16.0 4.0
Result of dividing 16.0 by 4.00 is 4.00.
Press enter key to continue ….
Welcome to <John Doe’>s Handy Calculator
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Exit
What would you like to do? 5
Thank you for using <John Doe’>s Handy Calculator
Note:
1) Replace the <John Doe’s> with your name
2) Make sure to properly word the output for the choices and result. Meaning, if user selects ‘1’ from menu, the prompt should be for ‘Addition’ not multiplication as shown in the example.
3) 3, 24.0 4.0 are shown in the example to emphasize that it is entered by the user and not part of the program. Underline and italics are not a requirement
4) Your program should allow input of integer or decimal numbers. The output should always be in decimals with two decimal digits as precision.
5) Make sure your program will continue displaying menu after result is shown and user has pressed enter key. Your program will exit only when user selects 5.
6) If user selects other than 1-‐5, show a message that they must select between 1 and 5. Give them a chance to re-‐enter. Continue until a valid number is entered