211k views
0 votes
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" "\\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 <> key; system("cls");} 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);}double addition(double num1, double num2){ return num1 + num2;}double multiplication(double num1, double num2){ return num1*num2;}

User Gonzo
by
3.8k points

2 Answers

3 votes

Answer:

im confused abut this rn

Step-by-step explanation:

User WatashiSHUN
by
3.5k points
1 vote

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;

}

Step-by-step 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!

User Alexei Khlebnikov
by
3.4k points