if-else-ladder-in-c++
Useful for if-else kind of conditional execution when we have more than two related conditional statements.
Syntax :
if(boolean_expression 1) { // Executes when the boolean expression 1 is true }else if( boolean_expression 2) { // Executes when the boolean expression 2 is true }else if( boolean_expression 3) { // Executes when the boolean expression 3 is true } else { // executes when the none of the above condition is true. }
Block Diagram :

Example:
WAP to give choice to user from menu to perform action.#include<iostream> using namespace std; int main( ) { int x ; cout<< "MENU\n----------\n1. for Hello\n2. for Bye\n-----------\n"; cout<< "Enter Your Choice: "; cin>>x; if(x==1) { cout<< "HELLO USER!!\n"; } else if(x==2) { cout<< "BYE USER!!\n"; } else { cout<< "INVALID CHOICE\n"; } return 0; }OUTPUT:
MENU ----------- 1. for Hello 2. for Bye ----------- Enter Your Choice: 3 INVALID CHOICE
Next topic is Nested-If in C++
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at info@prowessapps.in
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at info@prowessapps.in