home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Ebooks / Thinking in C++ V2 / C03 / Ifthen.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-25  |  800 b   |  32 lines

  1. //: C03:Ifthen.cpp
  2. // From Thinking in C++, 2nd Edition
  3. // Available at http://www.BruceEckel.com
  4. // (c) Bruce Eckel 1999
  5. // Copyright notice in Copyright.txt
  6. // Demonstration of if and if-else conditionals
  7. #include <iostream>
  8. using namespace std;
  9.  
  10. int main() {
  11.   int i;
  12.   cout << "type a number and 'Enter'" << endl;
  13.   cin >> i;
  14.   if(i > 5)
  15.     cout << "It's greater than 5" << endl;
  16.   else
  17.     if(i < 5)
  18.       cout << "It's less than 5 " << endl;
  19.     else
  20.       cout << "It's equal to 5 " << endl;
  21.  
  22.   cout << "type a number and 'Enter'" << endl;
  23.   cin >> i;
  24.   if(i < 10)
  25.     if(i > 5)  // "if" is just another statement
  26.       cout << "5 < i < 10" << endl;
  27.     else
  28.       cout << "i <= 5" << endl;
  29.   else // Matches "if(i < 10)"
  30.     cout << "i >= 10" << endl;
  31. } ///:~
  32.