Instead of using 1,2,3 I want the user to select from A,B,C but I'm having some problem finding the right solution. I have tried 'A' or '65' which is A in ASCII but I have no luck. How can I get the user to select a letter and then display the appropriate output?
Code:
#include <stdio.h> //Handles the keyboard input and screen output
#include <process.h> //Handles DOS system commands ("cls", "pause")
void(main)
{
//This part declares variables used by the program
int reply=0; //Users reply
int i, items = 'C'; //Loop counter, loop limit
//This part displays the menu items
system("cls");
printf("Welcome to MENU program!");
while (reply < items)
{
printf("\n\nHere are menu options that this program offers:");
//This part displays menu options
for (i = 'A'; i < items; i++)
{
printf ("\n%d. Option number %d", i, i);
}
printf ("\n%d. (or %d, ..., etc.) EXIT program.", items, (items+1));
printf ("\n"); // Changes the line
printf("\nTo terminate choose the option %d, or higher!", items);
printf("\nPlease choose the item to run (e.g. 1, ..., %d) ", items);
scanf("%d", &reply); // Inputs your reply
printf("Your choice was option number %d", reply); //Option
//Completes the processing for subsequent options
if (reply == 'A')
{
//Here complete actions for menu option number 1
printf ("\nOption number 1 is executed here!");
}
if (reply == 'B')
{
//Here complete actions for menu option number 2
printf ("\nOption number 2 is executed here!");
}
// ... (continue with options)
if (reply >= items)
{
//This completes actions for the option PROGRAM EXIT
printf (" which terminates this program!");
}
if (reply < 'A')
{
//Here is the "wrong reply" error message
printf ("\nChoice %d is out of range (retype 1, ..., %d).",
reply, items);
}
}
//The final displays
printf ("\n\nThank you for using this program. Good bye!");
printf ("\n"); // Changes the line
system("pause"); // DOS "Pause" command (for user to look at results)
}