Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<stack>
- using namespace std;
- float obliczONP (string x)
- {
- stack<float> q;
- float a,b;
- getline( cin, x);
- for(int i=0;i<x.length();i+=2)
- {
- if(x[i]>='0' && x[i]<='9')
- q.push(x[i]-48);
- else
- {
- b=q.top(); q.pop();
- a=q.top(); q.pop();
- if(x[i]=='+')
- q.push(a+b);
- else if (x[i]=='-')
- q.push(a-b);
- else if (x[i]=='*')
- q.push(a*b);
- else
- q.push(a/b);
- }
- }
- return q.top();
- }
- int main()
- {
- int a;
- string x;
- cout<<"1.Oblicz ONP"<<endl;
- cin>>a;
- if(a==1)
- {
- cout<<"Podaj obliczenie"<<endl;
- getline (cin, x);
- cout<<obliczONP(x);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement