Write the following in C. Write a program that reports the contents of a compres
ID: 672350 • Letter: W
Question
Write the following in C.
Write a program that reports the contents of a compressed-gas cylinder based
on the first letter of the cylinder’s color. The program input is a character representing
the observed color of the cylinder: ‘Y’ or ‘y’ for yellow, ‘O’ or ‘o’ for
orange, and so on. Cylinder colors and associated contents are as follows:
orange ammonia
brown carbon monoxide
yellow hydrogen
green oxygen
Your program should respond to input of a letter other than the first letters of
the given colors with the message, Contents unknown .
Explanation / Answer
#include <stdio.h>
int main()
{
char c;
printf( "Enter the alphabet coressponding to the color: " );
scanf( "%c", &c );
switch ( c )
{
case 'Y':
printf( "HYDROGEN ");
break;
case 'y':
printf( "HYDROGEN ");
break;
case 'o':
printf( "AMMONIA ");
break;
case 'O':
printf( "AMMONIA ");
break;
case 'b':
printf( "CARBON MONOXIDE ");
break;
case 'B':
printf( "CARBON MONOXIDE ");
break;
case 'G':
printf( "OXYGEN ");
break;
case 'g':
printf( "OXYGEN ");
break;
default:
printf( "Contents unknown ");
break;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.