Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Console Menu!! Any help?! Pls

Status
Not open for further replies.

Fori

Programmer
Joined
Jun 18, 2003
Messages
84
Location
MT
Hi

i'm relatively new to c++ altough i had some experince writing with other DOS enbled consoles!

I would like to have menu and the user selects items by pressing the numbers 1 to 6! Now, if a user inputs a char the whole program goes haywire!

Is there a way to make to user input only 1 to 6 or else how can i catch other char and output an error!


Thanks Nick
 
char ch;
printf("Please select a choice [1-6]:\n");
ch = fgetc(stdin);
if (ch < '1' || ch > '6') {
printf(&quot;Your choice must be between 1 and 6!!!\n&quot;);
}

I REALLY hope that helps.
Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top