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
......... mi2hej<br><br>ejid8eo19o1b2bxhxjxjdnneejk2929nr
Mila [183]

Answer:

hi  thsu si s5

Explanation:

brace use

5 0
2 years ago
Read 2 more answers
Write a program that defines an interface having the following methods: addition, subtraction, multiplication, and division. Cre
Tatiana [17]

Hello, you haven't provided the programing language in which you need the code, I'll explain how to do it using Python, and you can follow the same logic to make a program in the programing language that you need.

Answer:

1. # -*- coding: utf-8 -*-

2. #Python  

3. class Calculator:

4.     def add(self):

5.         print(a + b)

6.     def sub(self):

7.         print(a - b)

8.     def mul(self):

9.         print(a * b)

10.     def div(self):

11.         print(a / b)

12.  

13. obj = Calculator()

14. choice = 1

15. while choice != 0:

16.     a = int(input("\nEnter first number: "))

17.     b = int(input("Enter first number: "))

18.      

19.     print("\n0. EXIT")

20.     print("1. DIVISION")

21.     print("2. ADDITION")

22.     print("3. SUBTRACTION")

23.     print("4. MULTIPLICATION")

24.      

25.     choice = int(input("\nEnter your choice: "))

26.     if choice == 1:

27.         obj.div()

28.     elif choice == 2:

29.         obj.add()

30.     elif choice == 3:

31.         obj.sub()

32.     elif choice == 4:

33.         obj.mul()

34.     else:

35.         break

Explanation:

  • From lines 1 to 12 we define the object with four methods, addition, subtraction, multiplication, and division. Each method contains the operation between two variables inside a print function
  • On line 13 we instantiate our class
  • On line 14 we declare the variable choice that is going to store the operation that the user wants to perform
  • On line 15 we declare a while loop, this is going to keep running the program until the user wants to exit
  • From line 16 to 18 we ask the user to enter two numbers
  • From line 19 to 24 we print the possible operation, assigning a number for each operation, this indicates to the user what number to press for what operation
  • On line 25 we ask the user for the operation
  • From lines 26 to 35 we check the user input an accordingly we call the corresponding method to performs the operation
7 0
3 years ago
in speech writing, it can be defined as all aspect of your writing that help the reader move smoothly from one sentence to the n
serious [3.7K]

Answer:

Logical flow

Explanation:

In speech writing, LOGICAL FLOW can be defined as all aspects of your writing that helps the reader move smoothly from one sentence to the next, and from one paragraph to another.

With the Logical flow, one will be able to guide his thoughts coherently and sequentially in which Readers can fully absorb and easily understand the message.

5 0
2 years ago
A(n) ________
nignag [31]

Answer:

Technical specification document

Explanation:

6 0
2 years ago
Leo is in charge of advertising for the clothing lines of a large manufacturer. He uses his Google Ads Recommendations page to h
Sever21 [200]
D is the correct answer
4 0
3 years ago
Other questions:
  • Which protocol can be used to send ipv6 packets over an ipv4 network?
    5·1 answer
  • True or false. Embedding only part of a font is called presetting.
    14·1 answer
  • Which option correctly describes a DBMS application? A. software used to manage databases B. software used to organize files and
    7·2 answers
  • Generate an array x that has n=100 random numbers that are uniformly distributed over the interval [0,1) . Look up how to use th
    8·1 answer
  • For an alternative to the String class, and so that you can change a String's contents, you can use_________ .
    12·1 answer
  • Aubrey is on a Windows machine. She wants to back up her Halloween pictures on an external hard drive. Which of the following ta
    12·1 answer
  • David would like to send a letter to more than one hundred people. He would like the letter to have names and addresses inserted
    12·2 answers
  • Corey set up his presentation for delivery to his team.
    8·1 answer
  • Technological advances have made cyberbullying
    5·1 answer
  • WILL GIVE BRAINLIEST!!! Danielle is warehouse supervisor for a large shipping company. Most shipments need to leave the warehous
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!