/* Input validation loop (do-while) example taken from the ihypress.net Web site*/ #include int main (void) { char color; /* ask user for color */ do { printf ("Enter the color of the light (R,G,Y,A): "); scanf (" %c", &color); /* very important to leave space before %c here */ } while (color!='R' && color!='r' && color!='G' && color!='g' \ && color!='Y' && color!='y' && color!='A' && color!='a'); /* test the alternatives */ switch (color) { /* red light */ case 'R': case 'r': printf ("STOP! \n"); break; /* yellow or amber light */ case 'Y': case 'y': case 'A': case 'a': printf ("CAUTION! \n"); break; /* green light */ case 'G': case 'g': printf ("GO! \n"); break; /* no default case necessary here */ } return (0); }