Table Of Contents
Previous Section Next Section

Program 26: Trouble Area

This program is supposed to make sure that the width and height don't get too small. It works for width, but there's a problem with height.

  1 /************************************************
  2  * Test the logic to limit the width and height *
  3  * of a rectangle.                              *
  4  ************************************************/
  5 #include <iostream>
  6
  7 int main()
  8 {
  9     // The smallest legal value
 10     // of width and height
 11     const int MIN = 10;
 12
 13     int width = 5;      // Current width
 14     int height = 50;    // Current height
 15
 16     if (width < MIN) {
 17         std::cout << "Width is too small\n";
 18         width = MIN;
 19
 20     if (height < MIN)
 21         std::cout << "Height is too small\n";
 22         height = MIN;
 23     }
 24
 25     std::cout << "area(" << width << ", " <<
 26         height << ")=" <<
 27         (width * height) << '\n';
 28     return (0);
 29 }

(Next Hint 290. Answer 13.)

Table Of Contents
Previous Section Next Section