cpp / beginner
Snippet
Conditional Logic with If-Else
Conditional statements allow your program to make decisions based on certain criteria.
snippet.cpp
1
2
3
4
5
6
7
int score = 85;if (score >= 50) {std::cout << "Passed";} else {std::cout << "Failed";}
Breakdown
1
if (score >= 50)
Checks if the score is greater than or equal to 50.
2
else { ... }
Executes this block if the condition in the if-statement is false.