SOURCE FILE: floorSpace04.cpp


/* 
   Program to display the floor space for a room   
   
   Finished program.  All stubs code has been replaced with the final
   version of the function code.
*/

#include <iostream>
using namespace std ;

/* ================================== */
/* FUNCTION DECLARATIONS (PROTOTYPES) */
/* ================================== */

void directions(void);
       /* Print directions for using the program. */

int  GetDim(void);   
       /* Prompt the user for one dimension of a floor and 
          return that dimension */

int area(int length, int width);   
       /* Return the floor space (area of the floor) 
          given two dimensions (length and width). */

/* ================================== */
/* ================================== */

int main(void)   
{   
   int dim1,               // one dimension of the room     
       dim2,               // another dimension of the room 
       FloorSpace;         // area of floor in room         

         /* Step One: Print Directions for the user */
  directions() ;

        /* Step Two: Get the dimensions of the floor from the user */
  dim1 = GetDim();   
  dim2 = GetDim(); 
   
       /* Step Three: IF   either dimension is not positive
                           print an error message
                      ELSE Compute FloorSpace as product and 
                           print the answer out for the user to see
       */
  if ( (dim1 <= 0) || (dim2 <= 0) )      // invalid data 
   {    
      cout << "\nSorry, only positive dimensions are allowed.\n";
      cout << "Please reexecute the program.\n\n";
   }   
  else  // valid data 
   {   
      FloorSpace = area(dim1, dim2);   
      cout << "\nThe floor space is " << FloorSpace << " square feet.\n\n";
   }   

   return 0;
}   

/* ================================== */
/*       FUNCTION DEFINITIONS         */
/* ================================== */


/* ================================== */
void directions(void)   
{   
   cout << "\nThis program will give you the floor space ";
   cout << "in square feet\n" ;
   cout << "for a room of your choosing.\n\n" ;
}   
/* ================================== */
      

/* ================================== */
int GetDim(void)   
{   
   int dimension;      // one dimension of floor 
   
   cout << "Type one dimension of the floor in feet:  ";
   cin  >> dimension;

      // pass the value obtained back to the caller
   return dimension;   
}   
/* ================================== */
   
   
/* ================================== */
int area(int dim1, int dim2)   
{   
      // calculate the value and pass it to the caller
   return (dim1 * dim2);  
}   
/* ================================== */