IHYPRESS.NET
C
HOME | ASP | C | CSS | HTML | JAVASCRIPT | PERL | PHP | PYTHON | RUBY | SVG
CSelection Structures ❯ Nested if Statements
<03.02>
/* The traffic light program (nested ifs) */
#include <stdio.h> int main (void) { char color; /* ask user for color */ printf ("Enter the color of the light (R, G or Y): "); scanf ("%c", &color); /* test if color is red */ if (color == 'r' || color == 'R') printf ("STOP! \n"); else if (color == 'y' || color == 'Y') /* yellow color test */ printf ("CAUTION! \n"); else if (color == 'g' || color == 'G') /* green color test */ printf ("GO! \n"); else /* if not Y or G or R then invalid color */ printf ("INVALID color! \n"); return (0); }
Hergestellt in Deutschland / Made in Germany
Enter the color of the light (R, G or Y): G GO!
COPYRIGHT © 2015-2024 IHYPRESS.NET. A DIVISION OF IHY PRESS. ALL RIGHTS RESERVED.