Is this right? or cause it has error expected ';'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
Printable View
It runs now but when i enter a row number the program will be shut down..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("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;
return 0;
}
Typo on that dollar sign, replace it with percent sign:
Also, you forgot the & in front of rowChosen and sticksChosen, on the scanf() lines.Code:scanf("$d", sticksChosen);
Thank you so much! and now i will be doing the while loop in entire program?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;
or i will do the player code?
Code:printf("\nPlayer %d's turn! \n\n",player); player++;
if(player == 3)
player = player - 2;
My mistake!
Change the +1 to -1.Code:rows[rowChosen - 1] -= sticksChosen;
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
After making the last change, try compiling and running it. See what you get.
Post your latest code, so I can see what's doing.
This is my code.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;
}
printf("Please Enter a Row: ");
scanf("%d", &rowChosen);
printf("Please Enter Number of sticks: ");
scanf("%d", &sticksChosen);
rows[rowChosen -1] -= sticksChosen;
sum -= sticksChosen;
return 0;
}
You dropped this part:
Did you leave anything else out? Try it with the while loop back in place.Code:sum=rows[0]+rows[1]+rows[2];
while(sum>0) {
//All your other code goes in here.
}
I mean the while loop that is in #16 of this thread.
Hee Hee -- lazy bones! ;)