1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Zepler [3.9K]
3 years ago
10

Create the Following Menu in a loop so the menu will continually show until the user chooses to exit.AddMultiplyExitAdd a value

returning function to menu option 1 and menu option 2. This means that you will create two functions: an add function and a multiply function. The functions will receive two doubles and return a double. The following is code I have written to complete this assignment. When entering option 3 after entering option 1 or 2, it does not exit from the program. Also, the menu is appended instead of deleting everything and displaying the original menu.#include #include #include using namespace std;int options ();int option1 ();int option2 ();int option3 ();double addition (double num1, double num2);double multiplication (double num1, double num2);int main(){ int option = 0; cout << "1. Add" << endl; cout << "2. Multiply" << endl; cout << "3. Exit" << endl; cout << "Enter option 1 for addition, option 2 for multiplication, or option 3 to exit" "\nEnter an option: "; cin >> option; switch (option) { case 1:option1; int option1 ();{ double num1 = 0; double num2 = 0;// void int key = 0; cout << "\n Enter a number: "; cin >> num1; cout<< "\n Enter a second number: "; cin >> num2; double sum = addition(num1, num2); cout << "\n Sum is: " << sum <> key; system("cls");} break; case 2: option2; int option2 ();{ double num1 = 0; double num2 = 0;cout << "\n Enter a number:";cin >> num1;cout << "\n Enter a second number: ";cin >> num2;double product = multiplication(num1, num2); cout << "\n Product is: " << product << endl;system("cls");} break; case 3: option3; int option3(); {return 0;} break; default: cout << "\n Invalid number entered: ";}////do {main();}//while (option < 3);}double addition(double num1, double num2){ return num1 + num2;}double multiplication(double num1, double num2){ return num1*num2;}
Computers and Technology
1 answer:
ycow [4]3 years ago
4 0

Answer:

I have added the code again with the mistakes are corrected please see the comments in code. You have mistake in while loop condition.

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int options ();

int option1 ();

int option2 ();

int option3 ();

double addition (double num1, double num2);

double multiplication (double num1, double num2);

int main()

{  

jump:

int option = 0;  

cout << "1. Add" << endl;

cout << "2. Multiply" << endl;

cout << "3. Exit" << endl;

 cout << "Enter option 1 for addition, option 2 for multiplication, or option 3 to exit" "Enter an option: ";

  cin >> option;

   switch (option)  

{  

case 1:option1;  

int option1 ();

{  

double num1 = 0;  

double num2 = 0;

// void int key = 0;  

cout << " Enter a number: ";  

cin >> num1;  

cout<< " Enter a second number: ";  

cin >> num2;  

double sum = addition(num1, num2);  

cout << " Sum is: " << sum <<endl;

 } break;  

 case 2: option2;  

 int option2 ();

 {  

 double num1 = 0;  

 double num2 = 0;

 cout << " Enter a number:";

 cin >> num1;

 cout << " Enter a second number: ";

 cin >> num2;

 double product = multiplication(num1, num2);

  cout << " Product is: " << product << endl;

  //system("cls");

  }  

  break;

   case 3: option3;  

   int option3();

    {

 return 0;

 }  

 break;  

 default: cout << " Invalid number entered: ";

 }

 //do {main();}

 //while (option < 3); //you have mistake in this loop please have a look

 while (option<3)

 {

  goto jump;

 }

 

 }

 double addition(double num1, double num2)

 {

  return num1 + num2;

  }

 double multiplication(double num1, double num2)

 {

  return num1*num2;

  }

Explanation:

You can also do this by using goto statement in switch case and menu will be repeated until the user not select to exit and now it will work with the loop as well.

I hope it will help you!

You might be interested in
Using Python I need to Prompt the user to enter in a numerical score for a Math Class. The numerical score should be between 0 a
yaroslaw [1]

Answer:

<em>The program doesn't use comments; See explanation section for detailed line by line explanation</em>

<em>Program starts here</em>

def lettergrade(subject,score):

     print(subject+": "+str(score))

     if score >= 90 and score <= 100:

           print("Letter Grade: A")

     elif score >= 80 and score <= 89:

           print("Letter Grade: B")

     elif score >= 70 and score <= 79:

           print("Letter Grade: C")

     elif score >= 60 and score <= 69:

           print("Letter Grade: D")

     elif score >= 0 and score <= 59:

           print("Letter Grade: F")

     else:

           print("Invalid Score")

maths = int(input("Maths Score: "))

english = int(input("English Score: "))

pe = int(input("PE Score: "))

science = int(input("Science Score: "))

arts = int(input("Arts Score: "))

lettergrade("Maths Class: ",maths)

lettergrade("English Class: ",english)

lettergrade("PE Class: ",pe)

lettergrade("Science Class: ",science)

lettergrade("Arts Class: ",arts)

Explanation:

The program makes the following assumptions:

Scores between 90–100 has letter grade A

Scores between 80–89 has letter grade B

Scores between 70–79 has letter grade C

Scores between 60–69 has letter grade D

Scores between 0–69 has letter grade E

<em>Line by Line explanation</em>

This line defines the lettergrade functions; with two parameters (One for subject or class and the other for the score)

def lettergrade(subject,score):

This line prints the the score obtained by the student in a class (e.g. Maths Class)

     print(subject+": "+str(score))

The italicized determines the letter grade using if conditional statement

<em>This checks if score is between 90 and 100 (inclusive); if yes, letter grade A is printed</em>

<em>      if score >= 90 and score <= 100:</em>

<em>            print("Letter Grade: A")</em>

<em />

<em>This checks if score is between 80 and 89 (inclusive); if yes, letter grade B is printed</em>

<em>      elif score >= 80 and score <= 89:</em>

<em>            print("Letter Grade: B")</em>

<em />

<em>This checks if score is between 70 and 79 (inclusive); if yes, letter grade C is printed</em>

<em>      elif score >= 70 and score <= 79:</em>

<em>            print("Letter Grade: C")</em>

<em />

<em>This checks if score is between 60 and 69 (inclusive); if yes, letter grade D is printed</em>

<em>      elif score >= 60 and score <= 69:</em>

<em>            print("Letter Grade: D")</em>

<em />

<em>This checks if score is between 0 and 59 (inclusive); if yes, letter grade F is printed</em>

<em>      elif score >= 0 and score <= 59:</em>

<em>            print("Letter Grade: F")</em>

<em />

<em>If input score is less than 0 or greater than 100, "Invalid Score" is printed</em>

<em>      else:</em>

<em>            print("Invalid Score")</em>

This line prompts the user for score in Maths class

maths = int(input("Maths Score: "))

This line prompts the user for score in English class

english = int(input("English Score: "))

This line prompts the user for score in PE class

pe = int(input("PE Score: "))

This line prompts the user for score in Science class

science = int(input("Science Score: "))

This line prompts the user for score in Arts class

arts = int(input("Arts Score: "))

The next five statements is used to call the letter grade function for each class

lettergrade("Maths Class: ",maths)

lettergrade("English Class: ",english)

lettergrade("PE Class: ",pe)

lettergrade("Science Class: ",science)

lettergrade("Arts Class: ",arts)

7 0
3 years ago
You have informed your users that you need to bring the machine down at the end of the day to perform routine maintenance. Howev
PSYCHO15rus [73]

Answer:

shutdown -h +15 It is time for a shutdown!

Explanation:

In a work environment where there is an admin and users connected to the server when the admin wants to Give a 15-minute delay to allow users enough time to save their work data and logout from the system. the command above shuts down after 15 minutes delay and notifies the user with "It is time to shut down!".

8 0
3 years ago
How can i see what websites are visited on my wifi
grigory [225]

Answer:

If you want to view sites visited on a wireless network, you can check the logs stored by the wireless router to see what information is available. You may need to set your logging settings to capture the data you want.

Explanation:

5 0
2 years ago
Which statement is correct about operating systems? They are hardware devices. They include programs that help people do certain
katrin2010 [14]
<span>They include programs that help people do certain tasks. They include programs that control a computer. They store information being used by the CPU.</span>
3 0
2 years ago
Four differences between general and special purpose conputer in points.......
cupoosta [38]

Explanation:

hope this helps to uhh...

4 0
2 years ago
Other questions:
  • Read three integers from user input. Then, print the product of those integers. Ex: If input is 2 3 5, output is 30. Note: Our s
    6·1 answer
  • Temporary storage location for cutting and pasting
    9·1 answer
  • Which of the following parameters should match in order for a pair of routers to form an adjacency when running OSPFv2? (Points
    9·1 answer
  • 5. The hazardous component in most antifreeze is _____, which is extremely toxic to humans and animals. A) Calcium Carbonate B)
    13·2 answers
  • A tablet computer transmits a file over a wi-fi link to an access point.
    13·1 answer
  • You recently started working part-time in a retail store, and are learning about the reading devices your store uses. Your store
    10·1 answer
  • Which would be a responsible use of technology used by victims of cyberbullying?
    12·2 answers
  • Why must you be careful when handling a hard drive?
    10·1 answer
  • I am not a living being, I am a cylindrical shape that has three to eight sides. I never die. I can build anything again. What i
    5·1 answer
  • put together a shopping list of items that a first responder should always have at immediate disposal in a field kit. Using curr
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!