0

hi
i am trying to write a simple calculator.i have posted the code below,it works fine for one time solution. but i want the answer to be used for next calculation and also want to put a code to end the program.

int A,B,C;
	
	char op;

	cout<< "Enter a  number " <<endl;
	cin >> A;

	cout<<"Enter a operator " << endl;
	cin >> op ;

	cout<<"Enter a number " << endl;
	cin >> B;

	
		switch (op)
			{
			case '+':
				cout<<"The answer is "<<A+B<< endl;
				break;
			case '-':
				cout<<"The answer is "<<A-B<<endl;
				break;
			case '*':
				cout<<"The answer is "<<A*B<< endl;
				break;
			case '/':
				cout<<"The answer is "<<A/B<<endl;
				break;
			
		}
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by dusktreader
0

hi
i am trying to write a simple calculator.i have posted the code below,it works fine for one time solution. but i want the answer to be used for next calculation and also want to put a code to end the program.

1. You need some variable that will store the result.
2. You need to use a loop to keep asking for and processing input
3. You need that loop to have a termination criteria. A termination criteria is some condition that would signify that the loop should stop.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.