Using characters as menu choices. - C Language Basics

C examples for Language Basics:Console

Description

Using characters as menu choices.

Demo Code

#include <stdio.h>  
int main()/*from www.  jav a2 s. c  om*/
{ 
   char cResponse = '\0'; 

   printf("\na\tTurn the AC on\n"); 
   printf("b\tTurn the AC off\n"); 
   printf("\nEnter your selection: "); 
   scanf("%c", &cResponse); 

   if (cResponse == 'a'){ 
      printf("\nAC is now on\n"); 
   }
   if (cResponse == 'b') {
      printf("\nAC is now off\n"); 
   }
}

Related Tutorials