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;
			
		}

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.