IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
Earn Free Bitcoin
CSelection Structures ❯ switch Statement
<03.03>
/* The traffic light program (switch) */
#include <stdio.h> int main (void) { char color; /* ask user for color */ printf ("Enter the color of the light (R,G,Y,A): "); scanf ("%c", &color); /* 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; /* other color */ default: printf ("The color is not valid.\n"); } return (0); }
Hergestellt in Deutschland / Made in Germany
Enter the color of the light (R,G,Y,A): G GO!
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.