Decision Making in C++
Decision making structures helps to the programme evaluate one or more conditions in the program. If the condition is true it executes true statement otherwise it executes the false statement.
- If Statement
- If-else Statement
- Nested If statement
- Switch Statement
- Nested Switch Statement

If Statement:-
The if statement has a Boolean expression which contains one or more statements. The if condition is true it executes true statement.
if(boolean_expression) { /* statements will execute if the boolean expression is true */ }
Example:-
#include <iostream> using namespace std; int main(){ int a=10; if(a) { cout << "Print the value of a "<< a << endl; } return 0; }
If-else Statement:-
The if-else statement functions execute code statements if the test expression is true and some other code statements if the test expression is false.

Syntax:-
if(boolean_expression) { /* statements will execute if the boolean expression is true */ } else{ /* statements will execute if the boolean expression is false */ }
Example
#include <iostream> using namespace std; int main(){ int a=10,b=15; if(a > b) { cout << "Print the value of a "<< a << endl; } else{ cout << "Print the value of b "<< b << endl; } return 0; }
Nested If Statement:-
Nested If statement is used if or if-else inside another if or if-else.
Syntax:-
#include <iostream>
using namespace std;
int main(){
int a=12,b=7,c=5;
if(a > b) {
if(a > c){
cout << "Print the value of a "<< a << endl;
}
else{
cout << "Print the value of c "<< c << endl;
}
}
else{
if(b > c){
cout << "Print the value of b "<< b << endl;
}
else{
cout << "Print the value of c "<< c << endl;
}
}
return 0;
}
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.