View Single Post
Old 12-05-2008   #6
Malek
Registered Member
 
Malek's Avatar
 
Last Online: 11-04-2014
Join Date: Sep 2006
Posts: 1,302
Thanks: 102
Thanked 1,147 Times in 619 Posts
Groans: 8
Groaned at 1 Time in 1 Post
Default Re: c++ guru, urgent plz

I had this assignment last week, anyway here's the code.

Code:
#include <iostream>
using namespace std;

int main()
{

int number,answer;
char operators;

cout<<"Enter an arithmetic expression : ";
cin>>number;
answer=number;


do
{
	cin>>operators;
	if(operators!='=')
	{
		cin>>number;

		if(operators=='+') 
			answer+=number;

		if(operators=='-')
			answer-=number;
	}
}while(operators!='=');

cout<<"The answer is : "<<answer<<endl;

return 0;
}
Malek is offline   Reply With Quote