/* * ifelse2.c - if-else decision inside a while loop */ #include int main(void) { char cc; // declare char variable cc printf("The one character and press Enter: "); // prompt user printf("Type ? and press Enter for hlep: "); // prompt user while( (cc=getchar() ) != EOF ) // get a char from std-in // assign to cc // run the code between braces until cc contains EOF { if (cc=='?') { puts(" This program prints the character you entered."); puts(" Type CTRL-d to quit"); puts(" Type ? for help"); } else { printf("You entered %c.\n", cc); } getchar(); // flush newline from buffer printf(" Enter another character: "); // prompt for anohter char // go to top of while loop } printf("\n"); // display a newline at end of program return 0; // return 0 to calling program }