Write a program (or modify the one written for Lab 2) that displays the following menu and prompts the user for a selection. Once the selection has been made, display the selection back to the user. Then, ask the user for two numbers and perform the selected operation (+, -, *, /). Display the results back to the user (e.g. 2 + 3 = 5). When dividing, display an error message if the second number (denominator) is 0. 1)  Add two numbers 2)  Subtract two numbers 3)  Multiply two numbers 4)  Divide two numbers 9)  Exit program The program should: contain header comments as shown in class display a "hello" message before presenting the menu display the menu prompt the user for selection display the selection back to the user if the selection was invalid, display error message to user and then go to goodbye message if the selection was valid, prompt the user for two numbers if the operation is division, and the second number is 0, display error message to user and then go to goodbye message for any other scenario, perform the operation and display the results display a "goodbye" message before exiting the program HINT: The switch statement is ideal for menu-driven programs...   SAMPLE OUTPUT FOR VALID MENU SELECTION You entered 2, subtract two numbers SAMPLE OUTPUT FOR INVALID MENU SELECTION You entered 5, an invalid selection SAMPLE OUTPUT FOR ADD Please enter two numbers, separated by a space: 2 3 2 + 3 = 5 SAMPLE OUTPUT FOR DIVISION ERROR Please enter two numbers, separated by a space: 2 0 Division by zero is not possible

Question

Write a program (or modify the one written for Lab 2) that displays the following menu and prompts the user for a selection. Once the selection has been made, display the selection back to the user. Then, ask the user for two numbers and perform the selected operation (+, -, *, /). Display the results back to the user (e.g. 2 + 3 = 5). When dividing, display an error message if the second number (denominator) is 0.

1)  Add two numbers 2)  Subtract two numbers 3)  Multiply two numbers 4)  Divide two numbers

9)  Exit program

The program should:

  • contain header comments as shown in class
  • display a "hello" message before presenting the menu
  • display the menu
  • prompt the user for selection
  • display the selection back to the user
  • if the selection was invalid, display error message to user and then go to goodbye message
  • if the selection was valid, prompt the user for two numbers
  • if the operation is division, and the second number is 0, display error message to user and then go to goodbye message
  • for any other scenario, perform the operation and display the results
  • display a "goodbye" message before exiting the program

HINT: The switch statement is ideal for menu-driven programs...

 

SAMPLE OUTPUT FOR VALID MENU SELECTION

You entered 2, subtract two numbers

SAMPLE OUTPUT FOR INVALID MENU SELECTION

You entered 5, an invalid selection

SAMPLE OUTPUT FOR ADD Please enter two numbers, separated by a space: 2 3

2 + 3 = 5

SAMPLE OUTPUT FOR DIVISION ERROR Please enter two numbers, separated by a space: 2 0

Division by zero is not possible

Expert Answer

Want to see the step-by-step answer?

See Answer

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

See Answer
*Response times vary by subject and question complexity. Median response time is 34 minutes and may be longer for new subjects.
Tagged in
EngineeringComputer Science

Programing Language

Related Computer Science Q&A

Find answers to questions asked by student like you

Q: Design a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit...

A: Program plan:Use “for” loop to print a table of the Celsius temperatures 0 through 20 and their Fahr...

Q: CHALLENGE 3.16.2: Alphabetic replace. ACTIVITY Replace any alphabetic character with ' in 2-characte...

A: Program://include the required header files#include <iostream>#include <string>#include ...

Q: Construct an npda corresponding to the grammar S→aABB|aAA,A→aBB|b,B→bBB|A.

A: Firstly, we will convert the given grammar into GNFS → aABB|aAAA → aBB|bB → bBB|aBB|a

Q: For problem 10RQ for Business Informaiton Systems book by Paige Baltzan, the question asked what is ...

A: The terms Collective intelligence, Knowledge management and Crowdsourcing are related to each other ...

Q: Provide a situation that encompasses Confidentiality in the CIA triad

A: Answer:Situation of Confidentiality:Confidentiality comes under the C.I.A (Confidentiality Integrity...

Q: please solve this in python  //////////////// ////////////////   ////////////////   ////////////////

A: Program Instructions:Create three functions namely top(), body() and word() to print the different p...

Q: Eliminate all useless productions from the grammar S → aS|AB|λ, A → bA, B → AA. What language does t...

A: A useless production is basically a production which can never participate in the derivation of any ...

Q: Simplify the following equation using Boolean Identities: ~x~yz  + ~xy~z + x~y~z + x~yz + xy~z + xy...

A: 1)~x~yz + ~xy~z + x~y~z + x~yz + xyz~x~yz + ~xy~z + x~y~z + x~yz + xy~z + xyz( ~x~yz + x~yz ) + ( ~x...

Q: Use K-Maps to simplify each of the following: ~x~y~z + ~xyz + ~xy~z ~x~y~z + ~xy~z + x~y~z + xy~z ~...

A: Since there are 3 variables we construct the K-Map as follows and find the minimal cover of the map ...