[C++] Basic Variable comparison... If statements

Discussion in 'Mixed Languages' started by DARKOR04, Feb 14, 2011.

  1. DARKOR04

    DARKOR04 MDL Tester/Developer

    Jul 5, 2010
    495
    889
    10
    #1 DARKOR04, Feb 14, 2011
    Last edited by a moderator: Apr 20, 2017
    This example its from an online course I'm studying and find it very useful... [Beginners]

    Code:
    #include <iostream>    
    
    using namespace std;
            
    int main()                            // Most important part of the program!
    {
      int age;                            // Need a variable...
      
      cout<<"Please input your age: ";    // Asks for age
      cin>> age;                          // The input is put in age
      cin.ignore();                       // Throw away enter
      if ( age < 50 ) {                  // If the age is less than 50
         cout<<"You are pretty young!\n"; // Just to show you it works...
      }
      else if ( age == 50 ) {            // I use else just to show an example 
         cout<<"You are old\n";           // Just to show you it works...
      }
      else {
        cout<<"You are really old\n";     // Executed if no other statement is
      }
      cin.get();
    }
    I'm using code blocks compiler...
     
  2. Anakunda

    Anakunda MDL Senior Member

    Feb 6, 2010
    264
    9
    10
    How's that ppl at age of 50 are only old whilst at age above are really old.
    That's odd, I'm going to be 50 soon too:worthy:
     
  3. DARKOR04

    DARKOR04 MDL Tester/Developer

    Jul 5, 2010
    495
    889
    10
    Sooo Sorry....LOL Its a random number that is used.... HEHE