Table Of Contents
Previous Section Next Section

Program 22: Getting Too Big for Our Parameters

The idea of this code is simple: Make sure that size is not too large by limiting it to MAX. But that's now what we do.

  1 /************************************************
  2  * Test the logic to limit the size of a        *
  3  * variable.                                    *
  4  ************************************************/
  5 #include <iostream>
  6
  7 int main()
  8 {
  9     int size = 20;      // Size to be limited
 10     const int MAX = 25; // The limit
 11
 12     if (size > MAX)
 13         std::cout << "Size is too large\n";
 14         size = MAX;
 15
 16      std::cout << "Size is " << size << '\n';
 17      return(0);
 18 }

(Next Hint 304. Answer 4.)

Table Of Contents
Previous Section Next Section