@ Matticus: The effort is really praiseworthy.
@ ulti-killer: U seem to be a beginner, perhaps the following code would be easier for u.
Code 1:
Code:
#include <stdio.h>
#include <stdlib.h>
int main ( void )
{
char yesno[3], ch;
// Prompt and read whether the user want to continue or stop the program
printf("Continue (Y/N)? ");
// Loop if the user input the character other than Y, y, N and n
while (1)
{
fgets(yesno,3,stdin);
printf("\n");
if(yesno[1]=='\n')
if(yesno[0] == 'y' || yesno[0] == 'Y' || yesno[0] == 'N' || yesno[0] == 'n' )
break;
if(yesno[1]!='\n')
while (ch=getchar() != '\n');
printf("Invalid input. Please input again\n");
printf("Continue (Y/N)? ");
}
system("pause");
return 0;
}
Code 2:
Code:
#include <stdio.h>
#include <stdlib.h>
int main ( void )
{
char yesno;
// Prompt and read whether the user want to continue or stop the program
printf("Continue (Y/N)? ");
yesno=_getche();
fflush(stdin);
printf("\n");
// Loop if the user input the character other than Y, y, N and n
while (yesno != 'Y' && yesno != 'y' && yesno != 'N' && yesno != 'n')
{
printf("Invalid input. Please input again\n");
printf("Continue (Y/N)? ");
yesno=_getche();
fflush(stdin);
printf("\n");
}
system("pause");
return 0;
}