Condition
Here we write the crieteria with the help of relational operator the relational operators are
> Greater than
< Less than
> = Greater than or equal to
<= Less than and equal to
==Equal to
We can construct the conditional statement using if , else, else if ,
switch, case , turnery operator etc ...
If else
Syntax :-
if( condition)
{
true statement
}
else
{
false statement
}
If you understand if else condition then see some examples based on it
Example 1: Write a program to accept marks from user and checked he is passed or fail ??
Answer: #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"enter marks of student ";
cin>>a;
if(a>=33)
{
cout<<"Pass";
}
else
{
cout<<"Fail ";
}
getch();
}
Example 2: Write a program to accept age of user and checked he/ she is eligible for vote or not.
Answer: #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int age;
cout<<"enter age ";
cin>>age;
if(age>=18)
{
cout<<"You can vote !";
}
else
{
cout<<"You can't Vote ! ";
}
getch();
}
Example 3: Write a program to accept marks and check he/she is first division or not
Answer: #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int mks;
cout<<"enter marks of student ";
cin>>mks;
if(a>=60)
{
cout<<"You are first Division";
}
else
{
cout<<"You are not first division ";
}
getch();
}
Example 4: Write a Program to accept Run of a playr and check it's century
Answer: #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int run;
cout<<"enter run of a player ";
cin>>run;
if(run>=100)
{
cout<<"Your century is over";
}
else
{
cout<<"Your century is not over";
}
getch();
}
Example 5: Write a program to accept and check it is hot or cold .
Answer: #include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int t;
cout<<"enter temperature ";
cin>>t;
if(t>=30)
{
cout<<"Its hot";
}
else
{
cout<<"It's cold";
}
getch();
}
π IF you want to know How to solve Complex type of mathematical Problem in C++
Programming CLICK HERE
π IF you want to know How to use mathematical operator in c++ CLICK HERE
Our website:
π https://codemasternisha.blogspot.com/π
if you face any any problem or any issue about our website then fill the contact us page and write your issues in it ...
πππππππππππππ
KEEP SUPPORTING π !! KEEP LEARNING π !!
πππππππ
0 Comments