Help Needed

when i compile the following program it gives an error ISO forbid comparison between pointer and integer can anyone tell me what is the problem ??
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include<iostream>
#include<string>
#include<sstream>
using namespace std;
class car
{
      private:
      char make[20];
      char model[20];
      char color[20];
      int capacity;
      int xpos;
      int ypos;
      
      public:
      car()
      {
      strcpy(make,"Toyota");
      strcpy(model,"Corolla");
      strcpy(color,"White");
      capacity = 1300;
      xpos = 2;
      ypos = 3;
      }
      car(int xp, int yp, char*ma, char*mo, char*co, int ca)
      {
      xpos = xp;
      ypos = yp;
      strcpy(make,ma);
      strcpy(model,mo);
      strcpy(color,co);
      capacity = ca;
      }
      void setmake(char* n)
      {
           strcpy(make,n);
      }
      char* getmake(void)
      {
            return make;
      }
      void setmodel(char* m)
      {
           strcpy(model,m);
      }
      char* getmodel(void)
      {
            return model;
      }
            void setcolor(char* b)
      {
           strcpy(color,b);
      }
      char* getcolor(void)
      {
            return color;
      }
            void setcap(int c)
      {
           capacity = c;
      }
      int getcap(void)
      {
            return capacity;
      }
      void mov_fwd(void)
      {   
      xpos++;
      }
      void mov_back(void)
      {
      xpos--;
      //x--;
      }
      void mov_right(void)
      {
      ypos++;
      //y++;
      }
      void mov_left(void)
      {
      ypos--;
      //y--;
      } 
     int get_pos(void)
      {
      return xpos;
      }
      int get_pos1(void)
      {
      return ypos;
      }
};
int main()
{
    car c1(2,3,"Toyota","Corolla","White",1300);
    char g;
    cout<<"Data Of Car: "<<endl<<endl;
    cout<<"Make: "<<c1.getmake()<<endl<<"Model: "<<c1.getmodel()<<endl;
    cout<<"Color: "<<c1.getcolor()<<endl<<"Capacity(cc): "<<c1.getcap()<<endl;
    cout<<"\nTest Drive: "<<endl<<endl;
    while(g!="q")
    {
     cout<<"Waiting for command: ";
     cin>>g;    
     if(g=="f")
     {
     c1.mov_fwd();
     }
     else if(g=="b")
     {
     c1.mov_back();
     }
     else if(g=="r")
     {
     c1.mov_right();
     }
     else if(g=="l")
     {
     c1.mov_left();
     }
     else
     {
     cout<<"Invalid Command"<<endl;
     }
     } 
     cout<<"X= "<<c1.get_pos()<<endl<<"Y= "<<c1.get_pos1()<<endl;
     system("PAUSE");
}


Last edited on
Please use the code format for displaying code. It's the <> button on the right of the text box.

1
2
3
4
5
6
7
8
9
10

// Your code is hard to understand when laid out like that.

// The error seems to indicate you are comparing a integer
// to a memory address contained in a pointer. 
// You may need to dereference the pointer before 
// making the comparison. But that is just a guess 
// as I am not looking at code like that.

Last edited on
Well, this is actually rather simple. You declare 'g' as a character in main(); you then compare it to strings (look at lines such as while(g!="q")). The fix is simple- replace those quotes around each string (q, f, b, r, and l) with single-quotes. For example. while(g!='q') is valid code.
Last edited on
thanks it worked :)
Topic archived. No new replies allowed.