How to compare two variables with the help of If statement

How to compare two variables with the help of IF statement
How to compare two variables with the help of the If statement 

How to compare two variables with the help of an IF statement

If Statement: The ability to regulate the flow of your program, rental it builds choices on what code to execute, is effective to the applied scientist. 

The if statement permits you to regulate if a program enters a part of code or is not supported whether or not a given condition is true or false. 

An if statement is the most important statement in the C++ language.it can be used to decide control flow in C++ program. condition is true than if the statement executes the program.


Important Same Others If Else Statement

👉C If-Else Statement 

👉Java If-Else Statement 

👉Python If-Else Statement

if statement to examine a user-entered positive identification, your program will decide whether or not a user is allowed access to the program.

if(age>=18)

Here if conditions are true then the statement is executed otherwise the program is executed but the output does not show in your output screen. 


Syntax of if Statement

if(condition)

{

//Statement

}


How To Use if Statement in C++?

#include <iostream>


using namespace std;


int main()


{


  int age=18;


  if(age>=18)


 {


cout<<"You can drive Bike");


 }  


}


*****OUTPUT*****


You can drive Bike


How To  User input Statement in C++?

#include <iostream>


using namespace std;


int main()


{


 int age;


cout<<"Enter Your Age:";


cin>>age; 


if(age>=18  


{


cout<<"You can drive Bike";


}  


}


*****OUTPUT*****


Enter Your Age:21


You can drive Bike


If- Else Statement: A if-else statement is using a combination if statement. else statement can be used condition is false then else code is executed.

Syntax of if-else Statement

if(condition)

{

//Statement

}

else

{

//Statement

}


How To Use if-else Statement in C++? 

#include <iostream>


using namespace std;


int main()


{


    int age=17;


    if(age>=18)


{


   cout<<"You can Drive Bike";


}


else


{


cout<<"You can not Drive Bike";


} 


}


*****OUTPUT*****


You can not Drive Bike


How To Use if-else from user input Statement?

#include <iostream>


using namespace std;


int main()


{


int age;


cout<<("Enter your age:";


cin>>age;


if(age>=18)



{


cout<<"You can Drive Bike";


}


else


{



cout<<"You can not Drive Bike";


}  


}


*****OUTPUT*****


Please Enter Your Age:15


You can not Drive Bike


if-else-if statement: A if-else-if part of if conditional statement that executes only one condition at a time.it is all conditions are false then else part is executed.


Syntax of if-else Statement

if(condition)

{

//Statement 1;

}

else if()

{

//Statement 2;

}

else if()

{

statement 3;

}

else

{

statement 4;

}


How To Use if-else-if Statement in C++?

#include <iostream>


using namespace std;


int main()


{


int age=18;


if(age<=14)


{


cout<<"You are Kid";


}


else if(age<=18)


{


cout<<"You can Drive Bike";


}


else


{


cout<<"You can not Drive Bike";


}  


}


*****OUTPUT*****


You can  Drive Bike


How To Use if-else from user input Statement.

#include <iostream>


using namespace std;


int main()


{


int age;


cout<<"Enter your age:";


cin>>age;


if(age<=14)



{


cout<<"You are Kid";


}


else if(age<=18)



{


cout<<"You can Drive Bike";


}


else


{


cout<<"You can not Drive Bike";


}  


}


*****OUTPUT*****


Please Enter Your Age:13


You are Kid


Nested if statement: Nested if statement means one inside another so one if inside another if is called nested if statement. 


Syntax of Nested if Statement

if(condition)

{

if(condition)

{

//Statement;

}

}


How To Use Nested from Statement?

#include <iostream>


using namespace std;


int main()


{


int num=100;


if(num>25)


{


if(num<200)


{


cout<<" 200 number is greater than 100";


}  


}


}


*****OUTPUT*****


200 number is greater than 100


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.