Question

extra credit 1 Write a program that will display the following menu and prompt the user...

extra credit 1

Write a program that will display the following menu and prompt the user for a selection:

A)   Add two numbers
B)   Subtract two numbers
C)   Multiply two numbers
D)   Divide two numbers
X)   Exit program

The program should:

  • display a hello message before presenting the menu
  • accept both lower-case and upper-case selections for each of the menu choices
  • display an error message if an invalid selection was entered (e.g. user enters E)
  • prompt user for two numbers if A, B, C, or D was entered
  • if D entered, validate the second number is not zero
  • perform selected calculation (+, -, *, /) and display results
  • if X entered, display a goodbye message before exiting the program

Program output (what is displayed to the user) should be well-formatted (i.e. decimal places, if used, should be consistent), with descriptive text (e.g. The sum of 2 and 4 is 6), and "pleasing" to the eye (i. e. use blank lines or ============== to break up the presentation of the results).

============================================================================================================================================

extra credit 2

This extra-credit assignment

Modify the program written for Extra Credit #1 to continue prompting the user for a menu selection until the exit condition is entered. All other criteria from Extra Credit #1must still be met in Extra Credit #2.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
// add function that add two numbers
void add(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1+num2;
   cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result;
   return;
}
// subtract function that subtract two numbers
void subtract(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1-num2;
   cout << "The subtract of " << num1 << " and "<< num2 <<" is = "<< result;
   return;
}
// multiply function that multiply two numbers
void multiply(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1*num2;
   cout << "The multipication of " << num1 << " and "<< num2 <<" is = "<< result;
   return;
}

// divide function that divide two numbers
void divide(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   if(num2 ==0){// check denominator is zero or not
       cout << "Denominator can not be zero. Please enter the valid denominator "<< endl;
       cin >> num2;// if zero then ask valid denominator from user
   }
   float result=num1/num2;
   cout << "The division of " << num1 << " and "<< num2 << " is = "<< result;
   return;
}
//main function
int main(){
   cout << "Hello" << endl;//hello message
   cout << "======================================================================="<<endl;
   cout << "Menu "<< endl;//menu
   cout << "======================================================================="<<endl;
   cout << "a/A To add two numbers "<< endl;
   cout << "b/B To subtract two numbers "<< endl;
   cout << "c/C To multiply two numbers "<< endl;
   cout << "d/D To divide two numbers "<< endl;
   cout << "x/X Exit "<< endl;
   cout << "======================================================================="<<endl;
   char ch;
   cin >> ch;// taking options from user
   switch(ch){
       case 'a' : add();
                   break;
        case 'A' : add();
                   break;
       case 'b' : subtract();
                   break;
        case 'B' : subtract();
                   break;
       case 'c' : multiply();
                   break;
        case 'C' : multiply();
                   break;              
       case 'd' : divide();
                   break;
        case 'D' : divide();
                   break;
       case 'x' : cout << "Good Bye " << endl;
                          return 0;
        case 'X' : cout << "Good Bye " << endl;
                          return 0;
       default: cout << "Error: Invalid option "<< endl;// if invalid options
   }
return 0;                          
}


#include<iostream>
using namespace std;
// add function that add two numbers
void add(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1+num2;
   cout << "The sum of " << num1 << " and "<< num2 <<" is = "<< result<< endl;
   cout << "======================================================================="<<endl;
   return;
}
// subtract function that subtract two numbers
void subtract(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1-num2;
   cout << "The subtract of " << num1 << " and "<< num2 <<" is = "<< result<< endl;
   cout << "======================================================================="<<endl;
   return;
}
// multiply function that multiply two numbers
void multiply(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   int result=num1*num2;
   cout << "The multipication of " << num1 << " and "<< num2 <<" is = "<< result<<endl;
   cout << "======================================================================="<<endl;
   return;
}

// divide function that divide two numbers
void divide(){
   int num1,num2;
   cout << "Enter two numbers "<< endl;
   cout << "First :";
   cin >> num1;
   cout << "Second :";
   cin >>num2;
   if(num2 ==0){// check denominator is zero or not
       cout << "Denominator can not be zero. Please enter the valid denominator "<< endl;
       cin >> num2;// if zero then ask valid denominator from user
   }
   float result=num1/num2;
   cout << "The division of " << num1 << " and "<< num2 << " is = "<< result<< endl;
   cout << "======================================================================="<<endl;
  
   return;
}
//main function
int main(){
   cout << "Hello" << endl;//hello message
   cout << "======================================================================="<<endl;
   cout << "Menu "<< endl;//menu
   cout << "======================================================================="<<endl;
   cout << "a/A To add two numbers "<< endl;
   cout << "b/B To subtract two numbers "<< endl;
   cout << "c/C To multiply two numbers "<< endl;
   cout << "d/D To divide two numbers "<< endl;
   cout << "x/X Exit "<< endl;
   cout << "======================================================================="<<endl;
  
   char ch;
   cin >> ch;// taking options from user
   while(ch!='x'||ch!='X'){
      
       switch(ch){
           case 'a' : add();
                       break;
            case 'A' : add();
                       break;
           case 'b' : subtract();
                       break;
            case 'B' : subtract();
                       break;
           case 'c' : multiply();
                       break;
            case 'C' : multiply();
                       break;              
           case 'd' : divide();
                       break;
            case 'D' : divide();
                       break;
           case 'x' : cout << "Good Bye " << endl;
                              return 0;
            case 'X' : cout << "Good Bye " << endl;
                              return 0;
           default: cout << "Error: Invalid option "<< endl;// if invalid options
       }
   cout << endl;
    cin >> ch;
}
return 0;                          
}

Add a comment
Know the answer?
Add Answer to:
extra credit 1 Write a program that will display the following menu and prompt the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Menu-driven programs will display the menu options to the user and then prompt them for a...

    Menu-driven programs will display the menu options to the user and then prompt them for a menu choice. This program will display the following menu in the following format: Calculator Options: Calculate the area of a circle Calculate the area of a rectangle Calculate the area of a triangle Calculate the area of a trapezoid Calculate the area of a sphere Exit Enter your choice (1-6) Once the user enters a choice for the menu, the program should use a...

  • Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit...

    Write a calculator that will give the user this menu options: 1)Add 2)Subtract 3)Multiply 4)Divide 5)Exit . Your program should continue asking until the user chooses 5. If user chooses to exit give a goodbye message. After the user selections options 1 - 4, prompt the user for two numbers. Perform the requested mathematical operation on those two numbers. Round the result to 1 decimal place. Please answer in python and make it simple. Please implement proper indentation, not just...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • Write a program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B:...

    Write a program that displays this to the user. "Hot Beverage Menu" "A: Coffee $1.00", "B: Tea $ 0.75", "C: Hot Chocolate $1.25", "D: Cappuccino S2.50", "E: Exit Menu" Prompt the user to make a selection. Determine which item the user entered. Use a do-while loop that keeps repeating till the user selects E from the Menu. If the user has selected a valid beverage, prompt the user for how many cups they would like, and print out how much...

  • Write a program that displays a menu on the screen. The menu will give the user...

    Write a program that displays a menu on the screen. The menu will give the user four options - enter two integers, enter two decimal numbers (#.#), enter one integer and one decimal number, or quit. The inputs should be labelled a, b, c, or d, and you should enter in the letter to choose the appropriate option. Once the user selects the option, two numbers will be read in from the user. The numbers will be added together and...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • Description: In the main program create a menu system that will allow a user to choose...

    Description: In the main program create a menu system that will allow a user to choose from 3 option. 1. Fraction calculator 2. Grading schema 3. Biggest integer Program #1 Fraction calculator: You will start by prompting the user for two fractions in the main. The inputs should be two strings in the form #/#. You must account for both positive and negative numerators. Therefor -#/# is also a valid input. In a separate function create a program that will...

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • Write a program that performs the following: 1. Presents the user a menu where they choose...

    Write a program that performs the following: 1. Presents the user a menu where they choose between:              a. Add a new student to the class                           i. Prompts for first name, last name                           ii. If assignments already exist, ask user for new student’s scores to assignments              b. Assign grades for a new assignment                           i. If students already exist, prompt user with student name, ask them for score                           ii. Students created after assignment will need to...

  • Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to...

    Write MIPS code, please. Following: Write a program to be used by the Wisconsin DNR to track the number of Deer Hunting Licenses issued in a county and the state. It will display a menu with 5 choices numbered 1-5. They are (1) update the count, (2) display the number of licenses already issued to a county whose number is input, (3) display the county number and the number of licenses already issued to a range of counties whose starting...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT