Advertisement
Felanpro

Basic if statements in c++

Nov 2nd, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <cstdlib>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.    int age;                            // Need a variable...
  9.  
  10.   cout<<"Please input your age: ";    // Asks for age
  11.   cin>> age;                          // The input is put in age
  12.   cin.ignore();                       // Throw away enter
  13.   if ( age < 100 ) {                  // If the age is less than 100
  14.      cout<<"You are pretty young!\n"; // Just to show you it works...
  15.   }
  16.   else if ( age == 100 ) {            // I use else just to show an example
  17.      cout<<"You are old\n";           // Just to show you it works...
  18.   }
  19.   else {
  20.     cout<<"You are really old\n";     // Executed if no other statement is
  21.   }
  22.   cin.get();
  23.            
  24.            
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement