Making decisions
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- Write an if that checks temperature > 30
- Print "Hot" inside the if
- Add an else that prints "Pleasant"
Tutor
The tutor guides you toward the answer instead of handing it over. It uses your own Claude usage.
Quick check
In C++, what does == do?
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.