@Adak, Dude it almost done but when i compile it it has error. :/
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");
sum=rows[0]+rows[1]+rows[2];
while(sum>0)
{
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);
if(rowChosen > 3 || rowChosen < 1)
{
printf("Error! Enter number from 1-3!\n");
while (rowChosen > 3|| rowChosen < 1)
{
printf("Please Enter a Row Again: ");
scanf("%d", &rowChosen);
}
}
printf("Please Enter Number of sticks to remove: ");
scanf("%d", &sticksChosen);
switch(rowChosen)
{
case 1:
{
if(sticksChosen > 3 ||sticksChosen < 1)
printf("Error! Enter number from 1-3!\n");
while(sticksChosen > 3||sticksChosen < 1)
{
printf("Please Enter Number of sticks to remove again:");
scanf("%d", &sticksChosen);
}
}
break;
case 2:
{
if(sticksChosen > 5|| sticksChosen < 1)
{
printf("Error! Enter number from 1-5!\n");
}
while(sticksChosen > 5 || sticksChosen < 1)
{
printf("Please Enter Number of sticks to remove again:");
scanf("%d", &sticksChosen);
}
}
break;
case 3:
{
if(sticksChosen > 7 || sticksChosen < 1)
printf("Error! Enter number from 1-7!\n");
while(sticksChosen > 7 || sticksChosen < 1)
{
printf("Please Enter Number of sticks to remove again:");
scanf("%d", &sticksChosen);
}
}
break;
rows[rowChosen -1] -= sticksChosen;
sum -= sticksChosen;
}
return 0;
}