C++ Tutorial · Chapter 7 of 13
C++ If Else
Branching decisions.
if/else chooses different actions based on a condition.
You can nest if statements when a second decision depends on the first.
If sample
Try it Yourself »
#include <iostream>
using namespace std;
int main() {
int score;
cout << "Enter score: ";
cin >> score;
if (score >= 75) {
cout << "Passed" << endl;
} else {
cout << "Failed" << endl;
}
return 0;
}
Classroom Tips
- Compare with ==, not =.