23.7k views
3 votes
Write an appropriate control structure that will examine the value of a floating-point variable called

temp and print one of the following messages, depending on the value assigned to temp.

(a) ICE, if the value of temp is less than 0.

(b) WATER, if the value of temp lies between 0and 100.

(c) STEAM, if the value of temp exceeds 100.

Can a switch statement be used in this instance?

1 Answer

2 votes

Final answer:

The appropriate control structure for this scenario is an if-else statement.

Step-by-step explanation:

The appropriate control structure that can be used to examine the value of the floating-point variable temp and print the corresponding message is an if-else statement. Here is an example:

if (temp < 0) {
printf("ICE");
} else if (temp <= 100) {
printf("WATER");
} else {
printf("STEAM");
}

Since we need to evaluate multiple conditions, a switch statement is not suitable for this instance. Switch statements are typically used when we have a single value to compare against multiple constant values.

User Majken
by
7.2k points