Question #29627

Develop a menu-driven program that inputs two numbers and, at the user's options, find their sum, difference, product, or quotient.

Expert's answer

#include <iostream>

#include <conio.h>

using namespace std;

//main function

int main()

{

//variables

float fisrtnumber;

float secondnumber;

float sum;

float difference;

float product;

float quotient;

int ch;//choice

//input fisrt number and second number

cout<<"Enter first number: ";

cin>>fisrtnumber;

cout<<"Enter second number: ";

cin>>secondnumber;

do{

//show menu

cout<<"

1 - sum";

cout<<"

2 - difference";

cout<<"

3 - product";

cout<<"

4 - quotient";

cout<<"

5 - exit";

cout<<"Enter one menu item:";

cin>>ch;

switch(ch){

case 1:

sum=fisrtnumber+secondnumber;//find sum

cout<<"Sum = "<<sum<<"

";//show sum

break;

case 2:

difference=fisrtnumber-secondnumber;//find difference

cout<<"Difference =

"<<difference<<"

";//show difference

break;

case 3:

product=fisrtnumber*secondnumber;//find product

cout<<"Product =

"<<product<<"

";//show product

break;

case 4:

quotient=fisrtnumber/secondnumber;//find quotient

cout<<"Quotient =

"<<quotient<<"

";//show quotient

break;

}

}while(ch!=5);//exit

return 0;

}

#include <conio.h>

using namespace std;

//main function

int main()

{

//variables

float fisrtnumber;

float secondnumber;

float sum;

float difference;

float product;

float quotient;

int ch;//choice

//input fisrt number and second number

cout<<"Enter first number: ";

cin>>fisrtnumber;

cout<<"Enter second number: ";

cin>>secondnumber;

do{

//show menu

cout<<"

1 - sum";

cout<<"

2 - difference";

cout<<"

3 - product";

cout<<"

4 - quotient";

cout<<"

5 - exit";

cout<<"Enter one menu item:";

cin>>ch;

switch(ch){

case 1:

sum=fisrtnumber+secondnumber;//find sum

cout<<"Sum = "<<sum<<"

";//show sum

break;

case 2:

difference=fisrtnumber-secondnumber;//find difference

cout<<"Difference =

"<<difference<<"

";//show difference

break;

case 3:

product=fisrtnumber*secondnumber;//find product

cout<<"Product =

"<<product<<"

";//show product

break;

case 4:

quotient=fisrtnumber/secondnumber;//find quotient

cout<<"Quotient =

"<<quotient<<"

";//show quotient

break;

}

}while(ch!=5);//exit

return 0;

}

Learn more about our help with Assignments: C++

## Comments

## Leave a comment