if statement in C++
by Nideesh C on February 17, 2011 · 0 comments
in C++
The ability to control the flow of your program, letting it make decisions on what code to execute, is valuable to the programmer. The if statement allows you to control if a program enters a section of code or not based on whether a given condition is true or false. Below you will find sample conditional statements and a list of relational operators to use with the statements.
Relational Operators:
equal: ==
not equal: !=
less than: <
greater than: >
less than or equal to: <=
greater than or equal to: >=
not: !
and: &&
or: ||
If statements:
if () {
}
if/else statement:
if () {
}
else if () {
}
else {
}
Note: If you’re testing whether two things are equal or not, use ==, not =. Using = will set the first variable to the second.
example,
if (Age == 20) {
cout << “I am twenty years old.”
}
Example:
#include
using namespace std;
int main()
{
int age;
cout<<”Please input your age: “;
cin>> age;
cin.ignore();
if ( age < 100 ) {
cout<<”You are pretty young!\n”;
}
else if ( age == 100 ) {
cout<<”You are old\n”;
}
else {
cout<<”You are really old\n”;
}
cin.get();
}
Not Satisfied ? Just search & get the result
No related posts.
Tagged as:
C++ if statement,
how to use if statement,
if statement and c++,
if statement in C++,
if statement working,
working of if statement
Me, freelance system administrator having the qualification of Diploma in Electronics & Tele-communication + MCSE + CCNA + CST + 5 years of experience in IT field.
If you like This post, you can follow TheOnlineTutorials on Twitter.
Contact me Via email: support@theonlinetutorials.com
Subscribe to feed via Feed or EMAIL to receive instant updates.
Legal Disclaimer:All information found on the site is without any implied warranty of fitness for any purpose or use whatsoever. Content author/site administrator is not responsible for any loss occurred due to mistakes in this tutorial. Use this tutorial website at your own risk.