0

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

6
Contributors
8
Replies
66
Views
3 Years
Discussion Span
Last Post by 2384443
Featured Replies
  • 1
    Dani 1,532   3 Years Ago

    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 … Read More

1

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.

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

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

0

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

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.