I'm trying to create a game. In order to do it, I have two functions size() and ask_column().
Size() ask for the size of the grid wanted by the user. It return the number that should be 4 or 8.
int size() /*Ask for the size of the Takuzu that the user wants*/
{
int size;
do {
printf("Type the size of Takuzu that you want (only 4*4 and 8*8 are available): \n");
scanf("%d",&size);
}while(size != 4 && size != 8);
return(size);
}
Ask_column() ask for the column desired by the user. You enter the size of the grid in the matrix and it return a character that should be A to D if 4 4 grid and A to H if 8 8 grid.
char ask_column(int s) /*Ask the user in which column he wants to put his value*/
{
char column;
if (s==4)
{
do { /*Ask for the column if 4*4*/
printf("Enter the column of the value you want to enter (A to D): \n");
scanf("%c", &column);
} while (column != 'A' && column != 'B' && column != 'C' && column != 'D' && column != 'a' && column != 'b' &&
column != 'c' && column != 'd');
}
else
{
do { /*Ask for the column if 8*8*/
printf("Enter the column of the value you want to enter (A to H): \n");
scanf("%c", &column);
} while (column != 'A' && column != 'B' && column != 'C' && column != 'D' && column != 'E' && column != 'F' &&
column != 'G' && column != 'H' && column != 'a' && column != 'b' && column != 'c' && column != 'd' && column != 'e' && column != 'f' &&
column != 'g' && column != 'h');
}
return column;
}
The main issue I'm having is a repetition of the question from the Ask_column(). If size() is used, ask_column() will always ask the question 2 times. If not only one which is what I want.
int main()
{
int s;
s = size();
ask_column(s);
}
Return :
Type the size of Takuzu that you want (only 44 and 88 are available): 4 Enter the column of the value you want to enter (A to D): Enter the column of the value you want to enter (A to D):
int main()
{
int s;
s = 4;
ask_column(s);
}
Return :
Enter the column of the value you want to enter (A to D):
I really would like to know were this repetition is coming from.
Thanks to all the persons that would try to help !