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]
2 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]2 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
What type of media is a hard disk​
anyanavicka [17]

Answer:

A hard disk provides a high-capacity alternative to magnetic storage media. It contains metal platters coated with a magnetic layer. The platters usually spin continuously when a computer is on, storing data in different sectors on the magnetic disk.

Explanation:

5 0
3 years ago
WHAT DOES THE SCRATCH CODE BELOW DO?
Natasha_Volkova [10]

Answer:

the first one

Explanation:

3 0
2 years ago
The IT Department already has been testing Windows Server 2012 R2, and some time ago purchased licenses to convert all of its Wi
Nana76 [90]

Answer:

19

Explanation:

5 0
3 years ago
Question 9/10
Firlakuza [10]
They sometimes offer free service
5 0
3 years ago
Read 2 more answers
Intellectual property rights are exclusive rights that help protect both the created and the creation. IPR offers exclusively wh
dedylja [7]
IPR offers ownership of the intellectual property. The owner of the property has the right to a monetary gain from those who wish to use it.
8 0
2 years ago
Read 2 more answers
Other questions:
  • Write a statement that reads 5 successive integers into these variables that have already been declared : x1 x2x3x4 x5. Then wri
    7·1 answer
  • What is the output of the following Python program? try: fin = open('answer.txt') fin.write('Yes') except: print('No') print('Ma
    9·1 answer
  • If you specify a user without specifying a hostname, mysql will
    13·1 answer
  • Do AirPods Pro have a green flashing light when charging?
    11·2 answers
  • Using computer software, compare the 2016 year-to-date sales through February to the 2017 year-to-date sales through February fo
    15·1 answer
  • When developing e-business systems, an in-house solution usually requires a ____ for a company that must adapt quickly in a dyna
    11·1 answer
  • To color the h2 heading, what tag would you use?
    6·1 answer
  • Create a function names minElement() that takes an array of numbers as a paaramter and returns the min value of the array. The a
    9·1 answer
  • Write a SELECT statement that returns a single value that represents the sum of the largest unpaid invoices submitted by each ve
    5·1 answer
  • How to design remote access policy using the appropriate access controls for systems,applications, and data access
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!