// asterisksRectangle4.cpp
// Displays a few rectangles of asterisks, pausing between rectangles.
// Demonstrates void functions.

#include <iostream>
#include <string>

using namespace std;

void printRectangle(int rows, int columns);
void pause();

/*
 * Displays 3 rectangles of asterisks,
 * pausing between rectangles.
 *
 * Global variables:
 *    cin -- standard input stream
 *    cout -- standard output stream
 */
int main()
{
   printRectangle(5, 15);    // uses cout
   pause();                  // uses cin and cout
   printRectangle(7, 20);    // uses cout
   pause();                  // uses cin and cout
   printRectangle(10, 25);   // uses cout

   return 0;
}  // function main

/*
 * void printRectangle(int rows, int columns)
 *
 * Displays a rectangle of asterisks with the specified
 * number of rows and columns, where each cell consists
 * of a single asterisk, preceded by a space.
 *
 * If the parameter values are out of range, an error
 * message is dieplayed instead of the rectangle.
 *
 * Parameters:
 *    rows - the number of rows.
 *                  Must be integer in range [0, 22].
 *    columns - the number of columns
 *                  Must be integer in range [0, 40].
 *
 * Global variable:
 *    cout -- standard output.
 *       Precondition:  cout is ready to begin a line.
 *       Postcondition:  cout has ended a line.
 */
void printRectangle(int rows, int columns)
{
   // Check the number of rows:
   if ( rows < 0 || rows > 22 )  {
      cout << "rows=" << rows
                << ", must be in range [0, 22]." << endl;
      return;
   }  // if

   // Check the number of columns:
   if ( columns < 0 || columns > 40 )  {
      cout << "columns=" << columns
                << ", must be in range [0, 40]." << endl;
      return;
   }  // if

   // Print the rectangle:
   for ( int i = 0; i < rows; i++ )  {
      for ( int j = 0; j < columns; j++ )
         cout << " *";
      cout << endl;
   }  // for i
}  // function printRectangle

/*
 * void pause()
 *
 * Pauses the display. 
 * Prompts the user to press ENTER to continue.
 * Lets the program continue after the user presses ENTER.
 *
 * Global variables:
 *    cin -- standard input stream.
 *       Precondition:  The state of cin is true. (All
 *           previous interactive inputs were successful.)
 *       Postconditions:  The state of cin is still true,
 *           and cin has ended a line.
 *    cout -- standard output stream.
 *       Precondition:  none.
 *       Postcondition:  cout has ended a line.
 */
void pause()
{
   cout << endl << "Press ENTER to continue....";
   string line;
   getline(cin, line);
   cout << endl;
}  // function pause