home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch12 / inline1.cpp < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  40 lines

  1. //                    inline1.cpp
  2. //
  3. // Synopsis  - The program prompts for and accepts input of a
  4. //             decimal integer.  It then tests to see if that
  5. //             integer is even or odd.  The results of the
  6. //             test are displayed.
  7. //
  8. // Objective - Illustrates functions and control statements 
  9. //             in C++ and the use of an inline function that
  10. //             returns type bool.
  11.  
  12. // Include Files 
  13. #include <iostream.h>
  14.  
  15. // Function Prototypes
  16. inline bool odd ( int intvar );                          // Note 1
  17. // PRECONDITION:  none
  18. //
  19. // POSTCONDITION: If intvar is even, the function returns false.
  20. //                If intvar is odd the function returns true.
  21.  
  22. int main()                                                    
  23. {
  24.     int intvar;
  25.     cout << "Enter a decimal integer: ";
  26.     cin >> intvar;
  27.  
  28.     if ( odd( intvar ) )                              // Note 2
  29.         cout << intvar << " is odd.\n";
  30.     else
  31.         cout << intvar << " is even.\n";
  32.     return 0;
  33. }
  34.  
  35. //******************************odd()****************************
  36. inline bool odd( int intvar )                         // Note 3
  37. {
  38.     return( (intvar % 2) == 1 );                      // Note 4
  39. }
  40.