hey there! ok i need help figuring out what is wrong with my code. i have to write a program that does addition and subtraction in stacking. but all im getting is error. some advice would be greatly appreciated thanks
here is the code
#include <iostream>
#include <stack>
#include <string>
#include <cmath>
using namespace std;
int main()
{ stack <int> s;
int op1, op2;
string str;
int i;
cout<<"enter a post fix expression: ";
getline(cin, str);
for(i=0;i<str.length();i++)
{ if(isdigit(str[i]))
{ s.push(str[i]);
}else
{ char ch = str[i];
switch(ch);
{ case '+': //addition
op1=s.top();
s.pop();
op2=s.top();
s.pop();
s.push(op1+op2);
break;
case '-': //substract
op1=s.top();
s.pop();
op2=s.top();
s.pop();
s.push(op2-op1);
break;
case 'q': //quits the calculator
break;
}
}
}
if(!empty())
{ cout<<"the answer is: s.top()"<<endl;
}else
{ cout<<"error";
}
return 0;
}