Well this is a trivial piece of code that I'm working on just to understand the concepts of switch statements, and a bunch of other junk as I move along through it.
Basically the basics of C.
For this code however:
How do I correct the user if he entered another letter at the beginning? I tried throwing an if statement in there before the switch, and it didn't do much good. A while statement won't cover all 4 of the possible responses.Code:#include <stdio.h> int main () { char response; printf("This program is going to figure out how many days are left until your birthday.\n"); printf("\nDo you agree? (Y/N)"); scanf("%c", &response); switch (response) { case 'Y': case 'y': printf("Good job you crazy bastard.\n"); break; case 'N': case 'n': printf("You flying asshat, get the hell out of here.\n"); return -1; break; default: printf("Come on give me a Y or an N.\n"); /*while statement, an if statement, another scanf, what the hell do I do*/ } return 0; }
I'm not really sure what to do if the user enters a number or something to guide him the right way.
I'm working on it as I post this, but any ideas or responses are most welcomed.
Thanks.



LinkBack URL
About LinkBacks


