write a program that is able to compute some operations on an integer. The program writes the value of the integer and writes the following menu:
1. Add 1
2. Multiply by 2
3. Subtract 4
4. Quit
The program ask the user to type a value between 1 and 4. If the user types a value from 1 to 3 the operation is computed, the integer is written and the menu is displayed again. If the user types 4, the program quits.
#include <iostream>
using namespace std;
int main()
{
int a, MenuIn; //Moved 'a' here and declared another int MenuIn.
do{ //Your do-while would only repeat outputs, this lets the user also change the input.
cout<<"Enter a number:";
cin>>a;
cout<<endl << "1. Add 1"; //You will want to end lines or they will be printed one after another
cout<<endl << "2. Multiply by 2";
cout<<endl << "3. Subtract 4" <<endl << "4. Quit"<<endl; //You can use one cout if you like for different lines, just seperate them with 'endl'
cin >> MenuIn; //You need to let the user input something here.
if(a==1)cout<<"The sum is:"<<a+1<<endl;
if(a==2)cout<<"The product is:"<<a*2<<endl;
if(a==3)cout<<"The difference is:"<<a-3<<endl;
if(a==4)break;
}while(a<5); //Your-do while loop didn't change 'a' and so it would repeat forever it it didn't return (which it would),
cin.get(); //Don't use system("anything")
return 0;
}
is my work, correct. i was able to run it, but i am not sure if it is right.