The if statement is used to execute a statement, or group of statments only under certain conditions.
There are several possible formats:
To execute just one statement when the Boolean expression is true:
if(boolean expression) statement;
To execute one or more statements when the Boolean expression is true use { and } around the statements:
if(boolean expression) { statement; statement; ... }
There is an optional else that can be used when the Boolean expression is false:
if(boolean expression) statement; else statement;
To execute one or more statements when the Boolean expression is either true or false use { and } around the statements:
if(boolean expression) { statement; statement; ... } else { statement; statement; ... }
It is usually a good idea to put each statement on a separate line, but you can write if/else on one line:
if(grade<65) cout<<"fail"; else cout<<"pass";