Write a C++ program that reads a set of eight temperatures values and display the number of HOT, WARM and COLD records according to the following classification

HOT                                 
>35

warm
Between 27-35

cold
<27

by using if statment

The assignment itself is pretty good pseudocode already ...

if (temperature > 35)
{
    // do something
}
else if (temperature > 27)
{
    // do something else
}
else
{
    // do something else
}

Remember, we start at the first condition, and if it's true, we go into its code block. If it's not true, we move onto the next. So if the temperature is over 35, we go into the first block. However, if it's not, we check the second block. So when it checks the condition for the second block, we already know the temperature is 35 or under. Therefore, we can just check to see if it's over 27, and that will satisfy the 'between' requirement. If the temperature isn't over 27, we know it's 27 or under, and then we, by default, go into the third code block.

You need to retrieve eight temperatures from the user and loop through them, testing each one. You also need to figure out what to do within each code block.

if (temperature > 35)
{
    // do something
}
else if (temperature > 27) && (temperature < 35)
{
    // do something else
}
else
{
    // do something else
}

Marko, what if the temperature is 35? As I mentioned in my explanation, there's no need to expand on the middle conditional.

Sorry , wasn't even thinking about it because I've seen that the man is beginner , so I wanted him to get familliar with the use of && .

Should be:

if (temperature > 35)
{
    // do something
}
else if (temperature >= 27)
{
    // do something else
}
else
{
    // do something else
}
This article has been dead for over six months. Start a new discussion instead.