IHYPRESS PROGRAMMING
Tutorials and C programs with code and output for beginners
c programming
HOME | ASP | C | CSS | GNUPLOT | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
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 IHY PRESS Frankfurt am Main 60329 Deutschland