Codeloft
0 0 XP

Making decisions

7 min 20 XP + 10 for no hints

if runs code only when a condition is true, and else handles the other case. Conditions use comparison operators like >, >=, == and !=.

Join conditions with && (and) or || (or): if (age >= 13 && age <= 19) is true for teenagers.

The bool type holds true or false, which is a handy way to name a condition: bool isTeen = age >= 13 && age <= 19;

Example (inside main)
int marks = 72;
if (marks >= 40) {
    std::cout << "Pass" << std::endl;
} else {
    std::cout << "Try again" << std::endl;
}
Output
Pass
A single = stores a value. Use == when you want to compare.

Your tasks

0 of 3 done
  1. Write an if that checks temperature > 30
  2. Print "Hot" inside the if
  3. Add an else that prints "Pleasant"

Quick check

In C++, what does == do?

weather.cppChecked as you type
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.