Please Help! I need a peer review :(

Hello, I'm currently in C++ 101 at school and I need a peer review for my assignment by midnight tonight. I am taking this class online and there are no students available or they aren't responding on the class forums. Just a comment on any errors, unnecessary code or suggestions would be very appreciated!
The assignment ask me to make a game called "Nim"...

[size=90]You will write a program that implements the following version of the game of Nim.
Nim is a mathematical strategy game, which dates back to 16th century China. There are many
variations on this game, but the version we’ll be playing starts with a row of 11 sticks:
|||||||||||
On their turn a player may remove 1, 2, or 3 sticks from the pile. Players alternate taking turns,
and the play removing the last stick wins. Your game should feature two players alternating
turns. First, your program should print out a welcome statement and brief instructions. Then, you
should display the current game state and prompt player 1 for the number of sticks they should
remove:
After making sure they entered a valid response, you should remove the appropriate number of
sticks. If there are now zero sticks remaining, you should declare that player the winner and
end the program. Otherwise, the other player should take a turn.[/size]


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

using namespace std;
int playerinput;
const int MAXSTICKS = 11;///max number of sticks
int sticks = MAXSTICKS; ///number of sticks left
int whoplays = 1; ///1 is player ones turn, 2 is player twos turn
bool gamerunning = true;
int main()
{
    cout << "Welcome to Nim!" << endl;
    cout << "Players will take turns removing 1, 2, or 3 sticks from the initial 11.\n";
    cout << "The player removing the last stick wins! Player 1, it's your turn!" << endl;
    while ((gamerunning == true))
    {
        do
        {
            for (int i = sticks; i>0; i--)
            {
                cout << "|";
            }
            if (whoplays == 1)
            {
                cout << "\nPlayer 1, it's your turn!" << endl;
            }
            else
            {
                cout << "\nPlayer 2, it's your turn!" << endl;
            }
            cout << "How many sticks would you like to remove? (1, 2, or 3)..." << endl;

            cin >> playerinput;
            while (playerinput%1 !=0 || playerinput <= 0 || playerinput > 3 || playerinput > sticks)
            {
                cout << "INVALID INPUT \n Try Again..." << endl;
                for (int i = sticks; i>0; i--)
                {
                    cout << "|";
                }
                cout << "\n";
                cin >> playerinput;
            }

            sticks = (sticks-playerinput);
            if (sticks<1)
            {
                cout << "Congratulations Player " << whoplays<<", you win!\n\n\n";
                gamerunning = false;
            }
            if (whoplays == 1)
            {
                whoplays = 2;
            }
            else
            {
                whoplays= 1;
            }
        }
        while (sticks >0);
    }
    return 0;
}
Redundant expression
while (playerinput%1 !=0 || playerinput <= 0 || playerinput > 3 || playerinput > sticks)
Can be reduced to:
while (playerinput <= 0 || playerinput > 3)

Also, if you don't need global variables, then don't use them, all those variables you declared before main can be moved inside of main
I would probably place most of your global variables inside main, but in this small program it probably isn't too much of a problem.

Line 7: Like you made a const for MAXSTICKS, I would probably make constants for player 1 and 2's turns.
Line 14: The () around your equality is redundant.
Line 18: Normally for loops go from 0 to some value; I would probably change this to go the opposite direction.
Line 33: playerinput%1 !=0 will always be true...not sure what you were trying to test there.
Line 44: I would use -= here so it is clearer what you are doing.

Other: Your gamerunning variable seems to be useless as you always set it to false when the game is done, so there isn't really a point for it. Maybe you are going to follow up on this is another assignment?
thanks a lot, this helps. i'll make those changes!
Topic archived. No new replies allowed.