I'm trying to write a reusable, keyword, reusable, function that I could use that will detect for valid input of a menu that only uses characters.
For instance:
If the menu choices are S, G, and Q, I would write a menu function that will accept valid input as only: S, s, G, g, and Q, q.
I wanted to write a function similar to:
Code:
int GetValidInt(int min, int max) { /* is set greater than max so the loop will be entered*/ int input = max + 1; /* Loop assures valid input */ while( input < min || input > max ) { printf("Please enter an integer between"); printf(" %d and %d.\n", min, max); scanf("%d", &input); } return input; }
However, the S, G, and Q are not next to each other. Is there a way to do this without simply writing something like if menuchoice != S, G, Q, etc...
Maybe with ascii values???
Someone recommended using an array of characters? How exactly would I do this?
Thanks.
Mistro116