If statement in C++ programming allows you to control and execute a specific block of code if the condition is true or false based on some specific condition.
if(this condition is true)
execute this statement;
this expression | is true if |
---|---|
x == y | x is equal to y |
x != y | x is not equal to y |
x < y | x is less than y |
x > y | x is greater than y |
x <= y | x is less than or equal to y |
x >= y | x is greater than or equal to y |
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
cout<<"Enter a number less than 10: ";
cin>>num;
if(num <= 10) //if 'num' value Less then or Equal to 10 then
{
cout<<"What an obedient servant you are!"; //print this.
}
getch();
}
#include<iostream.h>
#include<conio.h>
void main()
{
int num;
cout<<"Enter a number less than 10: ";
cin>>num; //user enter value storing in 'num'.
if(num < 10) //if 'num' value is less then 10 then
{
cout<<"Entered value is Less then 10!"; //print this.
}
if(num == 10) //if 'num' value is equal to 10 then
{
cout<<"Entered value is Equal to 10!"; //print this.
}
if(num > 10) //if 'num' value greater then 10 then
{
cout<<"Entered value is greater then 10"; //print this.
}
getch();
}