Mega Code Archive

 
Categories / C Tutorial / Data Type
 

Compare characters to characters in if statement

#include <stdio.h> main() {   char cResponse = '\0';   printf("\n\tAC Control Unit\n");   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"); } AC Control Unit a Turn the AC on b Turn the AC off Enter your selection: 1