Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

if statement 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();
}

 
     
   
C++ Tutorial
 
  Introduction to C++
Introduction to C++
  Variables in C++
Variables in C++
  if statement in C++
if statement in C++
  Looping in C++
Looping in C++
  break & continue statements
break & continue statements
  Switch Case Statement
Switch Case Statement
  C++ Functions
C++ Functions
  Pointers in C++
Pointers in C++
  Arrays in C++
Arrays in C++
  Strings in C++
Strings in C++
  Structures in C++
Structures in C++
  C++ File I/O
C++ File I/O
  Typecasting in C++
Typecasting in C++
  C++ Classes
C++ Classes
  Recursion in C++
Recursion in C++
  Inheritance in C++
Inheritance in C++
  Initilization Lists in C++
Initilization Lists in C++
  Enumerated Types in C++
Enumerated Types in C++
  Templates in C++
Templates in C++
  C++ Preprocessors
C++ Preprocessors
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Blueprints for a successful presentation  Ebook Blueprints for a successful presentation
   
Download The Downline Code  Guru Secrets For Explosive MLM Growth  Ebook The Downline Code Guru Secrets For Explosive MLM Growth
   
Download Trading Fork Extreme Ebook Trading Fork Extreme
   
Download Combinatorial Algorithms  Ebook Combinatorial Algorithms
   
Download How To Accelerate Your Internet - A practical guide to Bandwidth Management and Optimisation using Open Source Software Ebook How To Accelerate Your Internet - A practical guide to Bandwidth Management and Optimisation using Open Source Software
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz