Advertisement

Newbie Question need help!!

Started by January 13, 2000 09:27 PM
0 comments, last by node_5r 24 years, 11 months ago
hey i am making a text base rpg. My first game! But In the first screen i want the user to be able to quit or to continue. I wast doing this with it. But when i run it and press y or no it always displays all my printf what can i do so it only displays the one for y or n? can you help me? #include main() { int y, n; y = '' ''; n = '' ''; printf("Welcome to my game!\n"); printf("press y to continue\n"); printf("press no to quit\n"); while (y != ''y''){ y = getc(stdin) printf("Thanks for coming!"); break; } while (n != ''n''){ n = getc(stdin) printf("Please come again!"); break; } printf("By node_5r"); return 0; }
Going into the loops your y doesn't equal 'y' *and* your n doesn't equal 'n'. Therefore after you leave your y loop you will go right into your n loop.

You might want to try instead:
int c = 0;
while (c != 'y' && c != 'n') {
c = getc();
if (c == 'y') {
// yes stuff
} else if (c == 'n') {
// no stuff
}
}

Edited by - SiCrane on 1/13/00 9:42:27 PM

This topic is closed to new replies.

Advertisement