NIM Game from book has 5 errors i cant understand.

Hi, thanks for reading this. Im currently reading a book called "Learn C++ by making games." ISBN = 978-1-58450-455-9
Console app
line 70 ( the else statemnt)
im using code::blocks, any better IDE ?
this book chapter 7 guides you through creating this Nim Sticks game,
ive worked on it till i just cant fix the last errors,
your help is greatly appreciated.

Ben

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
 #include <iostream>

using namespace std;

int main()
{
   cout << "Welcome to the Nim Game in C++ Written By Ben Miller." <<endl
   << endl;


   const bool HUMAN_PLAYER = true;
   const bool COMPUTER_PLAYER = false;

    char firstPlayer;
    bool validPlayer = false;

    bool currentPlayer;

    do {
        cout << "Whos turn is first {P}layer or {C}omputer?" << endl;
        cin >> firstPlayer;
        cout << endl;

        switch( firstPlayer )
        {
           case 'p':
           case 'P':
            validPlayer = true;
            currentPlayer = HUMAN_PLAYER;
            break;
           case 'c':
           case 'C':
             validPlayer = true;
            currentPlayer = COMPUTER_PLAYER;
            break;
            default:
            cout << "invalid entry: Please try again" << endl;
            break;

        }


    }
    while( !validPlayer);

    int nimsticks = 22;

    while( 0 != nimsticks)
    {
        cout << "There are " << nimsticks << " in the pile;" << endl;
        int currentplayermove = 0;
         if (currentPlayer=HUMAN_PLAYER)
         {
             bool validhumanmove = false;
             do
             {
                 cout << "how many sticks would you like to remove ";
                 cout << endl;
                 cin >> currentplayermove;
                 validhumanmove = (currentplayermove >0 && currentplayermove <5 &&
                                   currentplayermove <= nimsticks );
                                   if (!validhumanmove)
                                   {
                                       cout << "Wrong try again";
                                   } while (!validhumanmove);
             }


                                       else
                                       {
                                           int idealmove = (nimsticks % 5);
                                           if (idealmove == 0)
                                           currentplayermove = 1;
                                           else
                                            currentplayermove = idealmove;
                                            cout << endl << " The computer is taking " << currentplayermove << " sticks from the pile"
                                            << endl;

                                       }
                                       nimsticks -= currentplayermove;

                                       if(nimsticks ==0)
                                       {
                                           if(currentPlayer=HUMAN_PLAYER)
                                           {
}
                                            cout << endl << "you won";
                                            else
                                           {
                                               cout << endl << "Better luck next time";
                                           }
                                           else
                                           {
                                               currentPlayer = !currentPlayer;

                                           }
                                       }
             }

    }
return 0;
}
else statement must immediately follow if's closing braket "}". From your code I cannot tell if else from line 70 is paired with if from line 62, or maybe the one from line 52? Close all the brakets properly. The same goes for while in line 65 - shouldn't it be paired with some do?

In lines 88 and 92 you have another mismatched elses.
Last edited on
Topic archived. No new replies allowed.