Tortoise and Hare

I'm getting an error I don't understand when I compile in Bloodshed. This is for the old Tortoise and Hare problem. Any help is greatly appreciated.

I'm getting the following error:

58 E:\C++\Lab 4\tortoise.cpp ISO C++ forbids comparison between pointer and integer

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
#include <iostream>
#include <time.h>

using namespace std;

int main()
{
    char race[70] = " ";
    char* t = race;//tortoise pointer
    char* h = race;//hare pointer
    
    cout << "BANG!!!!" << endl;
    cout << "AND THEY'RE OFF!!!!" << endl;
    cout << "T" << endl;
    cout << "H" << endl;
    
         int j = 0;
         while (j =0, j < 71, j++)
         {
          srand(time(NULL));//generating random number
          j = rand() % 71;
           if (0 <= j <= 34)
            *t = race[j + 3];//50% of time tortoise moves 3 steps forward
           else if (35 <= j <= 49)
            *t = race[j - 6];//20% of time tortoise moves 6 steps back
           else if (50 <= j <= 70)//30% of time tortoise moves 1 step forward
            *t = race[j + 1];
           else if (0 <= j <= 13)
            *h = race[j];//20% of time hare sleeps
           else if (14 <= j <= 27)
            *h = race[j+9];//20% of time hare moves 9 steps forward
           else if (28 <= j <= 34)
            *h = race[j - 12];//10% of time hare moves 12 steps back
           else if (35 <= j <= 55)
            *h = race[j + 1];//30% of time hare moves 1 square right
           else if (56 <= j <= 70)
            *h = race[j - 2];//20% of time hare moves 2 squares back
         if (*t = *h)
            cout << "OUCH!!" << endl;
           else if (*t = race[j])
            cout << "T";
           else if (*h = race[j])
            cout << "H";
           else cout << race[j] << endl;
           if (*h > race[70])
            cout << "THE HARE WINS. YUCK." << endl;
           else if (*t > race[70])
            cout << "THE TORTOISE WINS! JEAH!" << endl;
           else if (*h > race[70] && *t > race[70])
            cout << "TIE GOES TO TORTOISE!" << endl;
    char command = ' ';
     cout << "Race again? (y/n)?" << endl;
      bool more = true;
       while (more)
        {
         cin >> command;
         command = toupper(command);
         if (command == "Y")
         more = true;
        }
    }
system("pause");
return 0;    
}


lines 17-21 look really strange to me
at line 18 did you mean for(j =0; j < 71; j++) ?
at line 22-36 you should use the OR operator: if (0 <= j || j <= 34)
at lines 38, 40 and 42 you used = instead of ==
at line 58 you should use single quotes: if (command == 'Y')
The loop at lines 54-60 is useless and would never stop
Last edited on
Topic archived. No new replies allowed.