Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create the Following Menu in a loop so the menu will continually show until the

ID: 3554421 • Letter: C

Question

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

Add 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 <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()

{         

    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;

            cout << "Press any key to continue: ";

//          cin >> 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;

}

Explanation / Answer

#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()
{   
int option = 0;
bool flag = true ;
  
do
{
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;
cout << "Press any key to continue: ";
// cin >> 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; flag = false;
int option3();
{
return 0;
}
break;
default:
cout << " Invalid number entered: ";
}
//
//do {main();}
//while (option < 3);
} while(flag) ;
}
double addition(double num1, double num2)
{
return num1 + num2;
}
double multiplication(double num1, double num2)
{
return num1*num2;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote