Originally Posted by
ervinako
i will delete the code? from #26 to #37 and put it in #46?..
Code:
#include <stdio.h>
int main ()
{
char ans;
do{
int rows[] = { 3, 5, 7};
int i, j;
int player =1;
int rowChosen, sticksChosen;
int sum;
printf("\n\n");
printf("\t\t******************************\t");
printf("\n\t\t****WELCOME TO GAME OF NIM****\t\t\n");
printf("\t\tErvin Ardiente & Orven Dumasig\t\n");
printf("\t\t******************************\t\n\n");
sum=rows[0]+rows[1]+rows[2];
while(sum>0)
{
if(rows[i])
{
printf("\nRow %d:", i+1);
}
printf("\nPlayer %d's turn! \n\n",player);
player++;
if(player == 3)
{
player = player - 2;
}
for(i = 0; i < 3; i++)
{
if(rows[i])
{
printf("\nRow %d:", i+1);
for(j = 0; j < rows[i] ; j++)
{
printf("\t|");
}
printf("\n");
}
}
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;
if(sum==0)
{
printf("\n\nPlayer %d You lose!\n\n", player);
}
}
printf("Do you wanna try again? (Y/N)");
scanf("%s", &ans);
}while (ans == 'Y' || ans == 'y');
return 0;
}
is this what you mean or what?..
it crashes the program..