Create C++ full program where a user enter two numbers, after a menu should prompt a user to
decide whether to:
i. Add
ii. Divide
iii. Subtract
iv. Multiply and
v. Exit
#include <iostream>
using namespace std;
int main()
{
int n1,n2,choice,result;
cout << "Enter the first number" << endl;
cin>>n1;
cout << "Enter the second number" << endl;
cin>>n2;
cout << " 1. Add" << endl;
cout << " 2. Divide" << endl;
cout << " 3. Subtract" << endl;
cout << " 4. Multiply" << endl;
cout << " 5. Exit"<<endl;
cout << "Choose from the menu above"<<endl;
cin>>choice;
switch (choice)
{
case 1:
result=n1+n2;
cout<<"The result is: "<<result<<endl;
break;
case 2:
result=n1/n2;
cout<<"The result is: "<<result<<endl;
break;
case 3:
result=n1-n2;
cout<<"The result is: "<<result<<endl;
break;
case 4:
result=n1*n2;
cout<<"The result is: "<<result<<endl;
break;
case 5:
break;
}
return 0;
}
Comments
Leave a comment