if else statement in C++
Syntax
if(condition) Print Statement 1 else Print Statement 2 // if condition is wrong than statement 2 will executedFor example
int marks=80; if(marks>33) cout<<"you are passed in examination"<<endl; else cout<<"you are failed in examination"<<endl;Example 1
#include<iostream.h>
int main()
{
float GPA;
cout<<"Enter your GPA"<<endl;
cin>>GPA;
if(GPA>=2.9)
{
cout<<"you are eligible for Laptop scheme."<<endl;
}
else
cout<<"you are not eligible for Laptop sachem."<<endl;
return 0;
system("pause");
};
Example 2
#include<iostream.h>
int main()
{
float marks;
cout<<"Enter your marks"<<endl;
cin>>marks;
if(marks>33)
cout<<”you are passed in examination ”<<endl;
else
cout<<”you are failed in examination”<<endl;
return 0;
system("pause");
};
Example 3
#include<iostream.h>
int main()
{
int a;
int b;
int c;
cin>>a;
cin>>b;
cin>>c;
if (a>b&&a>c)
cout<<”a is the greatest”<<endl;
if (b>c&&b>a)
cout<<”b is the greatest “<<endl;
if(c>a&&c>b)
cout<<”c is the greatest”<<endl;
else
cout<<”all the number you entered are equall<<endl;
return 0;
system("pause");
};


