# Thread: Game of Nim (PROJECT HELP!)

You need to still track how many sticks are left with the variable sum, so:

Code:
```#include <stdio.h>

int main ()
{
int rows[] = { 2, 4, 6};
int i, j,sum;

sum=rows[0]+rows[1]+rows[2];
while(sum>0) {
printf("\n\n\tWELCOME TO GAME OF NIM\t\n\n");

for(i = 0; i < 3,; i++)
{
printf("\nRow %d:", i+1);

for(j = 0; j < rows[i] ; j++)
{
printf("\t|");
}

printf("\t|");
}

//ask the user what row they want to pick sticks from
scanf() to get that number. (an int rowChosen)

//ask the user how many sticks they want to remove
scanf() to get that number. (an int sticksChosen)

rows[rowChosen+1] -= sticksChosen;
sum -= sticksChosen;
}
return 0;
}```

Code:
```printf("Please Enter a Row: ");
scanf("%d", rowChosen);
printf("Please Enter how many stick you will get: ");
scanf("\$d", sticksChosen);

rows[rowChosen+1] -= sticksChosen;
sum -= sticksChosen```
Is this right? or cause it has error expected ';'

2. Code:
```#include <stdio.h>

int main ()
{
int rows[] = { 2, 4, 6}; //Printing Game board
int i, j; // Variable in Printing Gameboard
int player =1; //The players
int rowChosen, sticksChosen; //Scan purpose
int sum;

printf("\n\n\tWELCOME TO GAME OF NIM\t\n\n");

for(i = 0; i < 3; i++)
{
printf("\nRow %d:", i+1);

for(j = 0; j < rows[i] ; j++)
{
printf("\t|");
}

printf("\t|");
}

printf("\n");

scanf("%d", rowChosen);
printf("Please Enter how many stick you will get: ");
scanf("\$d", sticksChosen);

rows[rowChosen+1] -= sticksChosen;
sum -= sticksChosen;

return 0;
}```
It runs now but when i enter a row number the program will be shut down..

3. Typo on that dollar sign, replace it with percent sign:

Code:
` scanf("\$d", sticksChosen);`
Also, you forgot the & in front of rowChosen and sticksChosen, on the scanf() lines.

Typo on that dollar sign, replace it with percent sign:

Code:
` scanf("\$d", sticksChosen);`
Also, you forgot the & in front of rowChosen and sticksChosen, on the scanf() lines.
Code:
```printf("Please Enter a Row: ");
scanf("%d", &rowChosen);
printf("Please Enter how many stick you will get: ");
scanf("%d", &sticksChosen);

rows[rowChosen+1] -= sticksChosen;
sum -= sticksChosen;```
Thank you so much! and now i will be doing the while loop in entire program?
or i will do the player code?

Code:
```  printf("\nPlayer %d's turn! \n\n",player);        player++;

if(player == 3)
player = player - 2;```

5. My mistake!
Code:
`rows[rowChosen - 1] -= sticksChosen;`
Change the +1 to -1.

The while loop is the whole game loop. Add your code to swap the player on turn, right inside it.

My mistake!
Code:
`rows[rowChosen - 1] -= sticksChosen;`
Change the +1 to -1.

The while loop is the whole game loop. Add your code to swap the player on turn, right inside it.
doing this will take the sticks in the game board or just take a stick in the program without deleting on the game board? cause
the game will be if you take a stick then

Row1: I I I
Row2: I I I I I
Row3: I I I I I I I

for example it will delete 3 from row1 so

Row1:
Row2: I I I I I
Row3: I I I I I I I

7. After making the last change, try compiling and running it. See what you get.

After making the last change, try compiling and running it. See what you get.
after compiling it and running it
It just ask me the row and stick to get then end of program..

9. Post your latest code, so I can see what's doing.

10. Code:
```#include <stdio.h>

int main ()
{
int rows[] = { 2, 4, 6}; //Printing Game board
int i, j; // Variable in Printing Gameboard
int player =1; //The players
int rowChosen, sticksChosen; //Scan purpose
int sum;

printf("\n\n\tWELCOME TO GAME OF NIM\t\n\n");

for(i = 0; i < 3; i++)
{
printf("\nRow %d:", i+1);

for(j = 0; j < rows[i] ; j++)
{
printf("\t|");
}

printf("\t|");
}

printf("\n");

printf("\nPlayer %d's turn! \n\n",player);
player++;
if(player == 3)
{
player = player - 2;
}

scanf("%d", &rowChosen);
printf("Please Enter Number of sticks: ");
scanf("%d", &sticksChosen);

rows[rowChosen -1] -= sticksChosen;
sum -= sticksChosen;

return 0;
}```
This is my code.

11. You dropped this part:

Code:
```    sum=rows[0]+rows[1]+rows[2];
while(sum>0) {
//All your other code goes in here.

}```
Did you leave anything else out? Try it with the while loop back in place.

You dropped this part:

Code:
```    sum=rows[0]+rows[1]+rows[2];
while(sum>0) {
//All your other code goes in here.

}```
Did you leave anything else out? Try it with the while loop back in place.
What you mean the while loop in my other thread?

13. I mean the while loop that is in #16 of this thread.

I mean the while loop that is in #16 of this thread.
let me code it first

15. Hee Hee -- lazy bones!