I just started coding so sorry for the stupid question. This is C programming.
When the user inputs Y
, the code runs as intended. If the user inputs N
or any other character, the program loops but it repeats the same line twice for some reason.
For example:
Input: Y
Output: The game will now start!
Input: N
Output: Waiting...
Would you like to start the game? <Y/N>:
is not a valid response
Would you like to start the game? <Y/N>:
As you can see the line doubles, how do I fix this?
do {
printf("Would you like to start the game? <Y/N>: ");
scanf("%c", &cGameStart);
if (cGameStart == 'Y')
printf("\nThe game will now start!\n");
if (cGameStart == 'N')
printf("\nWaiting...\n\n");
if ((cGameStart != 'Y') && (cGameStart != 'N'))
printf("%c is not a valid response\n", cGameStart);
} while (!(cGameStart == 'Y'));