Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include<iostream>
  2. #include<stack>
  3. using namespace std;
  4. float obliczONP (string x)
  5. {
  6. stack<float> q;
  7. float a,b;
  8. getline( cin, x);
  9.  
  10. for(int i=0;i<x.length();i+=2)
  11. {
  12.  
  13. if(x[i]>='0' && x[i]<='9')
  14. q.push(x[i]-48);
  15. else
  16. {
  17. b=q.top(); q.pop();
  18. a=q.top(); q.pop();
  19.  
  20. if(x[i]=='+')
  21. q.push(a+b);
  22. else if (x[i]=='-')
  23. q.push(a-b);
  24. else if (x[i]=='*')
  25. q.push(a*b);
  26. else
  27. q.push(a/b);
  28. }
  29. }
  30. return q.top();
  31. }
  32. int main()
  33. {
  34. int a;
  35. string x;
  36. cout<<"1.Oblicz ONP"<<endl;
  37. cin>>a;
  38. if(a==1)
  39. {
  40. cout<<"Podaj obliczenie"<<endl;
  41. getline (cin, x);
  42. cout<<obliczONP(x);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement