Professional Documents
Culture Documents
Labtrack 4
Labtrack 4
xhtml
Go Back
Completed Programs
The program must accept a character CH representing the color of traffic lights. The
program must print the output based on the following conditions.
- If CH is r or R, then the program must print the string value "RED - STOP".
- If CH is y or Y, then the program must print the string value "YELLOW - WAIT".
- If CH is g or G, then the program must print the string value "GREEN - GO".
- For any other values of CH, the program must print the string value "INVALID".
Example Input/Output 1:
Input:
r
Output:
RED - STOP
Example Input/Output 2:
Input:
Y
Output:
YELLOW - WAIT
Example Input/Output 3:
Input:
o
https://skillrack.com/faces/candidate/labcodeprograms.xhtml 1/2
6/28/2023 https://skillrack.com/faces/candidate/labcodeprograms.xhtml
Output:
INVALID
Show My Solution
#include<stdio.h>
#include<stdlib.h>
int main()
{
char s;
scanf("%c",&s);
s=toupper(s);
switch(s){
case 'R':
printf("RED - STOP");
break;
case 'Y':
printf("YELLOW - WAIT");
break;
case 'G':
printf("GREEN - GO");
break;
default:
printf("INVALID");
break;
}
}
https://skillrack.com/faces/candidate/labcodeprograms.xhtml 2/2