Branching with if and else in C++ is straightforward.
To compile and run this C++ program:
Note that in C++, you need parentheses around conditions, and braces are optional for single-statement blocks (though it’s often considered good practice to include them for clarity).
C++ does have a ternary operator (?:) for simple conditional expressions, which can be used as an alternative to simple if-else statements.