In Lab 2, you created a menu for a simple calculator
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 ADDPlease enter two numbers, separated by a space: 2 3
2 + 3 = 5
SAMPLE OUTPUT FOR DIVISION ERRORPlease enter two numbers, separated by a space: 2 0
Division by zero is not possible
LANGUAGE IS C++
Trending nowThis is a popular solution!
Step by stepSolved in 10 steps with 10 images
- 2.Create a visitors application that prompts the user for the number of visitors each day for the past 5 days and then displays the average number of visitors per day. (use & to accept new value) Use a for-loop for this question (1 to 5 , 5 iterations). The application output should look like same as following: Enter number of visitors on day 1: 150 Enter number of visitors on day 2: 220 Enter number of visitors on day 3: 180 Enter number of visitors on day 4: 300 Enter number of visitors on day 5: 320 The average number of visitors is 234arrow_forwardcreate a JAVA PROGRAM as a Currency Converter program. The program performs Currency Exchange operation between Saudi Riyals R, Dollars $, Euro € and British Pounds £. The program firstly shows a menu to the user which allows the user to choose one of the possible currency exchange operations and the last option in the menu should allow the user to end the program (see figure1). The menu should be like as figure 1. If the user enters a wrong choice, an error message should appear and the program asks the user to re-enter a correct number. When the user selects an operation, the program do the following: Prompt user to enter the amount to be changed Input amount Calculate and print the result. Once the user presses any key, the menu appears again and the user can choose a new operation. Your output should be similar to the result in figure 2. Note: Currency change rate is assumed to be known in your program. For example, to convert from Riyals to Euro, change rate = 0.22751799.…arrow_forwardWrite the code to allow the user to enter a list of positive integers via input boxes and add each number entered to the lstNums list box. Use a Do-While or Do-Until Loop to let the user continue to enter numbers until -1 is entered. Do not add the -1 entry to the list box. In visual Basic please.arrow_forward
- Fill in the first blank to compute the total number of calories for all items on the menu and fill in the 2nd blank to compute the number of items on the menu:arrow_forwardIt is given 12 balls that are all the same weight except for one that is heavier or lighter. Additionally, it is provided with a two-pan balance. In each scenario, the balance is used. You may place any number of the 12 balls on the left pan and the same number on the right pan and press a button to begin weighing; three alternative results exist: the weights are equal, the balls on the left are heavier, or the balls on the left are lighter. Develop a technique for determining which ball is the odd one out and whether it is heavier or lighter than the others using the fewest feasible uses of the balance. Solve the weighing issue for the situation of 39 balls, one of which is known to be strange.arrow_forwardWrite a program that uses the following menu to keep track of student information: 1) Enter a student 2) Quit If the user chooses 1, prompt the user to enter a grade level (to be chosen from the given menu) and a test score. Keep track of the following: • Total number of Freshmen, Sophomores, Juniors, and Seniors • Total number of students entered • Total of all test scores entered When the user chooses to quit, calculate: • The percentage of students that fall into each category • The average of all the test scores entered Display your results as shown. Input validation: • The user must choose valid options from the menus. • The user must enter a test score between 0 and 100.arrow_forward
- You are a Chemistry major who has to create a program for first time chemistry lab users. The Erlenmeyer flask contains a nitric acid solution. When the student presses a button, 0.5 mL of NaOH solution can be added to a buret, which is set up over the Erlenmeyer flask. An indicator is added to the solution being titrated. The indicator is a substance that changes to blue when the reaction is complete (endpoint). You determine the amount of mixture that will cause this reaction to occur. Create a titration simulator that will allow a student to add up to 18 mL of titrant. Notify the student when the mixture turns blue. In Python please :)arrow_forwardWrite a program that generates a random number in the range of 1 through 1000, and asks the user to guess what the number is. If the user guess is higher than the random number, the program should display Too high, try again. If the users guess is lower than the random number, the program should display Too low, try again. If the user guesses the number, the application should congratulate the user and generate a new random number so the game can start over. If the user doesn't want to continue the game the user should type an appropriate stop symbol to terminate the program (such stop conditions were discussed in the class). For each game iteration, count the number of guesses made by the user and display them. The program should contain the following functions: check_guess(): this function checks if the user's guess is lower, higher or equal to the random number. random_gen(): function that generates one random number for one game iteration main(): the function where the program…arrow_forwardYou have been hired by a local smoothie shop to a program that will calculate the cost of a smoothie order. The shop sells four types of smoothies in three different sizes: Small (20 oz), Medium (32 oz) and Large (40 oz). Your program should use a menu for the type of smoothie and a second menu for the smoothie size. Calculate the total cost of the order including tax and display a bill for the smoothie. See the Sample Output. The sales tax rate is 4.5%. Use named constants to hold the cost per ounce of each of the products and the sales tax rate. Use the constants in your calculations and wherever else they are appropriate in your program. Product Cost per Ounce Banana $0.62Strawberry $0.60 Mango $0.48 Blueberry $0.57 Project 3 is a continuation of Projects 1 and 2. You will modify your code from Project 2 to make the program modular for this part of…arrow_forward
- Write an application that counts by five from 5 through 500 inclusive and that starts a new line after every multiple of 50 (50,100,150 and so on).Save the file as CountByAnything.javaarrow_forwardThis is C code for a math program. Here are the instructions. Here is my code. After I complete my initial problem instead of going back through the While loop back to the menu, it jump streight to division and then crashes. Please take a look and fix. ********* For this project, you will create a program that will test the user’s proficiency in solving different types of math problems. The program will be menu-driven. The user will select either addition, subtraction, multiplication, or division problems. The program will then display a problem, prompt the user for an answer, and then check the answer displaying an appropriate message to the user whether their answer was correct or incorrect. Instructions This week you’ll complete your project. First, check through for any corrections you need to make – perhaps your instructor as comments from Week 4 that you want to incorporate. This week, make sure you add functionality to keep statistics on the number of correct answers…arrow_forwardIn this game, the player is in a land full of dragons. The dragons all live in caves with their large piles of collected treasure. Some dragons are friendly and share their treasure. Other dragons are hungry and eat anyone who enters their cave. The player approaches two caves, one with a friendly dragon and the other with a hungry dragon, but doesn’t know which dragon is in which cave. The player must choose between the two. The program should look like this in the console, the player input is in bold: You are in a land full of dragons. In front of you, you see two caves. In one cave, the dragon is friendly and will share his treasure with you. The other dragon is greedy and hungry and will eat you on sight. Which cave will you go into? (1 or 2) 1 You approach the cave... It is dark and spooky... A large dragon jumps out in front of you! He opens his jaws and... Gobbles you down in one bite! Process finished with exit code 0 Questions for this assignment Are dragons really…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education