Related questions
Create a new file (in Dev C++)
In Lab 2, you created a menu for a simple calculator
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 user for selection
- echo the selection back to the user
- if the selection was invalid, display error message to user and then loop back to menu
- if the selection was valid, prompt the user for two numbers
- if the operation is division, and the second number is zero, display error message to user and then loop (with new prompt) until non-zero number is entered
- for any other scenario, perform the operation and display the results
- use loop to present menu again and ask for another selection
- continue looping until user selects exit condition
- display a goodbye message before exiting the program
HINT: The loop should continue until some condition is false. What is that condition? When should it be set false? Consider using a flag variable for the loop...
NOTE: Make sure to handle integer division (int/int = int, but we want decimal result!)
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 2 images
- In Javaarrow_forwardPlease refer to the picture and also rewrite it as a for loop and do- while loop. Please show your source code for all three thank you.arrow_forwardHarlan A. Brothers and John A. Knox discovered that as the value of x gets larger, the value of the expression gets closer and closer to e. Write a program that evaluates this expression for x = 1, 2, 3, and so on until the absolute difference between the expression’s value and the value of e calculated by the library function (exp) is less than 0.000001. Display the value of x that causes your loop to exit along with both the final approximation of e and the value of e calculated by the (exp) function. Show seven decimal places. IN C PROGRAMMING LANGUAGE PLEASE AND COMMENT EVERY STEP OF ITarrow_forward
- write a c++ program Use a pretest loop to allow the user to enter data until they input 0 for the purchase amount. Do all of your output in main(). Make it look like this. Don’t forget your underlines won’t be immediately underneath. Use methods for the following: getPurchaseAmt() Get the monthly purchase amount from the user. Include an error-trap around this input value so the user will have to enter a positive number (0r 0 to end the loop). Return the purchase amount. displayMenu() Display a menu of the membership types for the user to choose from, as follows: Membership Types: Premium Plus Standard Enter choice (1, 2, or 3): This method only displays. There is nothing to return, so it will be a void method. You will call this method from getType(). getType() Call the displayMenu() method and get the membership type from the user. Include an error-trap around the menu and choice so the program will not continue until the user enters a valid choice. Return the choice....arrow_forward6. What is the loop control variable? Explain the mechanism to run and to stop a loop! Give an example!arrow_forwardIn C++ What type of loop requires the user to manually terminate the loop? a. counter-controlled while loop b. sentinel-controlled while loop c. eof-controlled while loop d. counter-controlled for looparrow_forward
- The function print_last_line in python takes one parameter, fname, the name of a text file. The function should open the file for reading, read the lines of the file until it reaches the end, print out the last line in the file, report the number of lines contained in the file, and close the file. Hint: Use a for loop to iterate over the lines and accumulate the count. For example: Test Result print_last_line("wordlist1.txt") maudlin The file has 5 lines.arrow_forwardFor this portion of the lab, you will reuse the program you wrote in Lab 3A. Redesign this solution so that some portions of the code are repeated. In lab 3 you validated input to ensure that the user entered inputs within certain values. If the user entered an invalid value, the program terminated. Now you will add a loop such that the user gets three changes to enter a valid value. If the user enters an invalid value more than three times in a row, the program should issue an error message and terminate. Save the program as firstname_lastname_Lab4a.py where you will replace firstname and lastname with your actual first and last name. Test all conditions prior to submitting. If the user enters an invalid value, then the program will issue an error message and terminate immediately. (Do NOT accept further data). Part B: Draw Something In this portion of the lab you will draw an inverted triangle using loops. ********** ********* ******** ******* ****** ***** **** *** ** *...arrow_forwardTrue or False? A loop with no condition is equivalent to a loop with true as condition (i.e., an infinite loop). Hint: Please follow the re True Falsearrow_forward
- A while loop is a form of Select one: a. transitive loop b. definite loop c. indefinite loop d. finite looparrow_forwardWrite a for loop that prints out the numbers 15 down to 5, one number per line. Declare all variables needed, only write the code required. Do not write a complete program. Comments and system libraries should not be included.arrow_forwardWrite a for loop to calculate the sum of the numbers from 0 through 9 and display the sum in an alertbox (No other output, just use an alertbox)?arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education