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 : http://girfahelp.blogspot.in/p/c-language.html
     ********************************************/

#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");
                 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 colour */
       default:
                 printf ("valid. color choice\n");
   }

  
}

No comments:

Post a Comment