#include <stdio.h>
int
main (void)
{
char colour;
do
{
printf ("Enter the colour of the light (R,G,Y,A): ");
scanf (" %c", &colour);
}while (colour!='R' && colour!='r' && colour!='G' && colour!='g'
&& colour!='Y' && colour!='y' && colour!='A' && colour!='a');
switch (colour)
{
case 'R':
case 'r':
printf ("STOP! \n");
break;
case 'Y':
case 'y':
case 'A':
case 'a':
printf ("CAUTION! \n");
break;
case 'G':
case 'g':
printf ("GO! \n");
break;
}
return (0);
}
Legend: preprocessor directives | variable declarations | main program | helper functions | user-defined structures |
|
Enter the colour of the light (R,G,Y,A): b
Enter the colour of the light (R,G,Y,A): x
Enter the colour of the light (R,G,Y,A): G
GO!
|
No comments:
Post a Comment