So I'm trying to ask the user if they would like to repeat my program and I am getting a weird result now and then. It doesn't happen everytime and I havn't been able to figure out what triggers it.
To me it looks like it is assigning the 'return' after I enter 'q' to repeatProgram instead of the 'q' but I have no Idea why.
The output when it works:
to exit enter q, to continue enter y.
s
you've entered s, that isn't a valid option.
The output when it fails:
to exit enter q, to continue enter y.
q
you've entered
, that isn't a valid option.
The code:
char RepeatProgramPrompt()
{
char repeatProgram;
do
{
printf("\nTo exit enter q, to continue enter y.\n");
scanf("%c%*c", &repeatProgram);
repeatProgram = tolower(repeatProgram);
if(repeatProgram != 'y' && repeatProgram != 'q')
{
printf("\nYou've entered %c, that isn't a valid option.\n", repeatProgram);
}
}while(repeatProgram != 'y' && repeatProgram != 'q');
return(repeatProgram);
}
So my question is, why is this happening? it will work fine for a bunch of tries and then just fail.
Sorry if I've formatted this wrong it is my first post.