ISO C++ forbids comparison between pointer and intiger

below is a small snippet of code I am having my problem with.
ISO C++ forbids comparison between pointer and integer and that is the message I get when I try to compile.
it probably does not help that I dont even know what a pointer exactly is

if (choice==1&&choice>ranNum2)
the little part above is where C++ is spitting out an error, and obviously the 4 variants of that.... originally I had them saying if (choice=="Higher"&&choice>ranNum2) I got the same error


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
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////Variables//////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

int ranNum=0,ranNum2=0,ranMax=200,guess,scoreP1=0,scoreAI=0,round=0;
//coloring
int scoreP1C=241;
int scoreAIC=242;

void score();
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////Functions//////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

int main()
{
    string choice []={"Higher","Lower"};
    do
    {
    srand((unsigned)time(NULL));//init random funct
    ranNum=rand()%ranMax;
    ranNum++;
    cout<<"The number is "<<ranNum<<".\nWill the next number be Higher or Lower than\n"<<ranNum<<"?\n";
    srand((unsigned)time(NULL));
    ranNum2=rand()%ranMax;
    ranNum++;
             for (int i=0;i<2;i++)
              {
                  cout<<i+1<<"-"<<choice[i]<<endl;
              }
    if (choice==1&&choice>ranNum2)
    {
             cout<<"\nGood job, "<<ranNum<<" is > "<<ranNum2<<" you get a point.\n";
             scoreP1++;
             round++;
             cout<<"\nPlayer 1 has "<<scoreP1<<" points.\n";
             cout<<"The AI player has "<<scoreAI<<" points.\n";
             cin.get();
             Sleep(1000);
    }
    if (choice==2&&choice<ranNum2)
    {
             cout<<"\nGood job, "<<ranNum<<" is < "<<ranNum2<<".\n";
             scoreP1++;
             round++;
             cout<<"\nPlayer 1 has "<<scoreP1<<" points.\n";
             cout<<"The AI player has "<<scoreAI<<" points.\n";
             cin.get();
             Sleep(1000);               
    }
    if (choice==1&&ranNum!>ranNum2)
    {
             cout<<"\nSorry, your guess was wrong "<<ranNum<<" is lower than "<<ranNum2<<".\n";
             scoreAI++;
             round++;
             cout<<"\nPlayer 1 has "<<scoreP1<<" points.\n";
             cout<<"The AI player has "<<scoreAI<<" points.\n";
             cin.get();
             Sleep(1000);
    }
    if (choice==2&&ranNum!<ranNum2)
    {
             cout<<"\nSorry, your guess was wrong "<<ranNum<<" is higher than "<<ranNum2<<".\n";
             scoreAI++;
             round++;
             cout<<"\nPlayer 1 has "<<scoreP1<<" points.\n";
             cout<<"The AI player has "<<scoreAI<<" points.\n";
             cin.get();
             Sleep(1000);
             
    }
    while (round<10)
    score();
}

I apologize for the length of the code, but c++.com didnt let me use the [spoiler][/spoiler]bbc tag :(
choice is an array of strings: string choice []={"Higher","Lower"};

what do you think should happen when you compare that array with 1 or any other number?
putting it like that it wont work, however Like I said I also tried naming a string from that array "Higher" and that returned comparison between distinct pointer types `std::string*' and `const char*' lacks a cast... and that is something I do not understand at all.

when the program does compile the user will use the number 1 or 2 to activate Higher or Lower
Last edited on
when the program does compile the user will use the number 1 or 2 to activate Higher or Lower


Perhaps you should actually attempt to get input from the user prior to determining what they've input.
derp moment... that is a wonderful Idea
lets just add a few lines to ask them
mmkay the initial issue was fixed. when I have time ill post about the new problem, my russian friend and I ran into
Topic archived. No new replies allowed.