Having trouble creating

Hi all,
With the code I've written so far, it is able to add subtract, and separate functions from either input or being read from txt files. I was able to do this by using if statements within a while loop reading ints and chars. Now I'm trying to make it so that it can read squares based on if a number is written x^ (i.e. 5^ = 25). I'm not really sure where to go from here, and any advice on how to approach would be greatly appreciated!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 #include <iostream>
using namespace std;
int main()
{
	int s, result=0;
	char x;
	cin >> result;
	while(cin >> x >> x >> s)
	{
		if(x=='^')
		{
			result=result+(s*s);
		}
		else if(x=='+')
		{
			result=result+s;
		}
		else if(x=='-')
		{
			result=result-s;
		}
		else if(x==';')
		{
			cout << result << endl;
			result=s;
		}
	}
	cout << result << endl;
	return 0;
}
Topic archived. No new replies allowed.