Monday, 30 January 2017

Traffic Light Programe

NIELIT O Level January 2016 Solved

Q 7 : c) Write a program that displays the recommended actions depending on the color of a traffic light using the switch statement.

Solution : 

/* *******************************************
     Girfa : Student Help
     Traffic Light Program
     for more program visit :

#include <stdio.h>
void main (void)
   char color;

   /*  colour input */
   printf ("Enter the colour of the light (R,G,Y,A): ");
   scanf ("%c", &color);

   /* test the posibility */      
   switch (color)
       /* red light */
       case 'R':
       case 'r':
                 printf ("STOP! \n");

       /* yellow or amber light */
       case 'Y':
       case 'y':
       case 'A':
       case 'a':
                 printf ("CAUTION! \n");
       /* green light */
       case 'G':
       case 'g':
                 printf ("GO! \n");

       /* other colour */
                 printf ("valid. color choice\n");


No comments:

Post a Comment