please help

could use a second pair of eyes. please and thank you
i wanted to use "expression" as an operator and run loops

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
  #include <iostream>
#include <cmath>
#include  <stack>
using namespace std;


int main() {
        int num;
        string expression (int) ;
        
        cout << "Enter stack function\n";
        cout << "start by entering #'s followed by operators (+,-,/,*";
        cin >> num;
        cin >> expression;
       get.num;
       bool result=false;
       stack<int> s;
       for(int i=0;i<expression.length();i++)
       {
           if(expression[i]=='+')
           {
               int a=s.top();
               s.pop();
               int b=s.top();
               s.pop();
               s.push(a+b);
           }
           else if(expression[i]=='-')
           {
               int a=s.top();
               s.pop();
               int b=s.top();
               s.pop();
               s.push(b-a);
           }
           else if(num[]=='*')
           {
               int a=s.top();
               s.pop();
               int b=s.top();
               s.pop();
               s.push(b*a);
           }
           else if(expression[i]=='/')
           {
               int a=s.top();
               s.pop();
               int b=s.top();
               s.pop();
               if(a==0)
               {
                   result=true;
                   cout<<"result=error: division by zero"<<endl;
                   break;
               }
               else
               s.push(b/a);
           }
           else
           s.push(num[]-'0');
       }
       if(result==false)
       {
          
           int x;
           if(s.empty()==false)
           {
               x=s.top();
               s.pop();
               cout<<"result="<<x<<endl;
           }
       }
   
   cout << "end-of-file";
   return 0;
}
Last edited on
could use a second pair

What does that mean? Or do you just ask what all the compiler messages are for?
 In function 'int main()':
14:16: error: cannot bind 'std::istream {aka std::basic_istream<char>}' lvalue to 'std::basic_istream<char>&&'
In file included from /usr/include/c++/4.9/iostream:40:0,
                 from 1:
/usr/include/c++/4.9/istream:872:5: note: initializing argument 1 of 'std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&&, _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = std::basic_string<char>(int)]'
     operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp& __x)
     ^
15:8: error: 'get' was not declared in this scope
18:33: error: request for member 'length' in 'expression', which is of non-class type 'std::string(int) {aka std::basic_string<char>(int)}'
20:27: warning: pointer to a function used in arithmetic [-Wpointer-arith]
20:30: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
28:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
28:35: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
36:24: error: expected primary-expression before ']' token
44:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
44:35: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
60:23: error: expected primary-expression before ']' token
 
closed account (z05DSL3A)
string expression (int) ; this is a function declaration.

I would probably guess it is a little confused about get.num; as well.

else if (num[] == '*') and s.push (num[] - '0'); missing a index for the subscript of num.
Last edited on
Topic archived. No new replies allowed.