info@thistimebd.com

Friday 29th of March 12:51:46pm

Write an appropriate control structure that will examine the value of a floating pont variable called temp and print one of the following massages, depending on the value assigned to temp

Write an appropriate control structure that will examine the value of a floating

point variable called temp and print one of the following massages, 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 is less than 0,

(c) STREAM, if the value of temp is less than 0,

Can a Switch statement be used in this instead?


Solution: 

A Switch cannot be used because:

1. The test involves floating-point quantities rather than integer quantities.

2. The test involves ranges of values rather than exact values.

#include<stdio.h>

int main()

{

float temp;

printf("Enter a Temparature ");

scanf("%f",&temp);

if(temp<0)

printf("ICE");

else if(temp>=0 && temp<=100)

printf("WATER");

else if(temp>100)

printf("STREAM");

}