Answer to Question #313803 in C for Suhani Goel

Question #313803

Identifying a compressed gas cylinder is

based on the first letter of the

cylinder’s color printed on the cylinder. For Example

‘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.

Write a C program using switch case to identify the type of gas compresse

d

in a given cylinder.



1
Expert's answer
2022-03-18T12:13:52-0400
#include <stdio.h>


int main() {
    char ch;
    char* gas;


    printf("Enter a gas cylinder's color: ");
    scanf("%c", &ch);


    switch (ch) {
    case 'o':
    case 'O':
        gas = "Ammonia";
        break;
    case 'b':
    case 'B':
        gas = "Carbon monoxide";
        break;
    case 'y':
    case 'Y':
        gas = "Hydrogen";
        break;
    case 'g':
    case 'G':
        gas = "Oxygen";
        break;
    default:
        gas = "Unknown";
    }


    printf("There is %s in a given cylinder\n", gas);


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS