SYNTAX
if (condition) {
code in c++
}
EXAMPLE
//IF ELSE STATEMENTS IN C++
#include <iostream>
using namespace std;
int main()
{
cout<<endl;
cout<<"__SELECTION STRUCTURE__"<<endl;
cout<<"-> impliment in our program by if-else ladder statement.";
cout<<endl;
int age;
cout<<"enter your age :"<<endl;
cin>>age;
if((age<1) && (age>0)){ //we can use like that and operator.
cout<<endl;
cout<<"you are not yet born. "<<endl;
cout<<endl;
}
else if(age==18){
cout<<endl;
cout<<"you are a kid but you can come in pary."<<endl;
cout<<endl;
}
if(age<18){
cout<<endl;
cout<<"you are not able to come in party. "<<endl;
cout<<endl;
}
else if(age>18){
cout<<endl;
cout<<"you are able to come in party."<<endl;
cout<<endl;
}
else{
cout<<"you can come to the party."; // in this program first we entry in our
//program then conditiOn check hori hai
// ye hai selection control structure.
}
return 0;
}
//OUTPUT
// __SELECTION STRUCTURE__
// -> impliment in our program by if-else ladder statement.
// enter your age :
// 17
// you are not able to come in party.
Comments
Post a Comment