/* This program will read in a room size and then compare carpet sizes to the room size.
   Erik Johnson 100890362 */

#include <iostream>
#include <math.h>

using namespace std;

bool isInt (double value) {
  double dummy;
  return bool(modf(value, &dummy) == 0);
}

double sqr(double value) { return value * value; }

int main (void) {

  // Variables
  double rwid = -5, // Initial values are negative so they will run the rwid and rlen while loop.
         rlen = -5,
         swap, // Variable used to interchange dim1 and dim2 if dim1 is greater than dim2.
         cwid = -5, // Initial values are negative so they will run the cwid and wlen while loop.
         clen = -5;

  // While loop takes input into dim1 and dim2 and makes sure they are acceptable dimensions.
  while (rwid <= 0 || rlen <= 0) {
    cout << "Please enter room dimensions: ";
    cin >> rwid >> rlen;
    if (rwid <= 0 || rlen <= 0) {
      cout << "Those dimensions are invalid." << endl;
    } // end if
  } // end while

  // Interchanges values of rwid and rlen if rwid is bigger than rlen by using swap variable.
  if (rwid > rlen) {
    swap = rwid;
    rwid = rlen;
    rlen = swap;
  } // end if

  // While loop runs until carpet dimensions of 0 by 0 are entered.
  while (cwid != 0 && clen != 0) {

    // Output asks for carpet dimensions and in put reads in carpet dimensions.
    cout << "Please enter carpet dimensions (0 0 to stop): ";
    cin >> cwid >> clen;

    if (cwid != 0 && clen != 0) {

      // Interchanges values of cwid and clen if cwid is bigger than clen by using the swap vairable.
      if (cwid > clen) {
        swap = cwid;
        cwid = clen;
        clen = swap;
      } // end if

      // Now for the three possible outputs based on the input values.
      if (cwid == rwid && clen == rlen) {
        cout << "The carpet is a perfect fit." << endl;
      } else if (cwid < rwid && clen < rlen) {
        cout << "The carpet cannot be used." << endl;
      } else {
        cout << "The carpet can be trimmed to size." << endl;
      } // end if
    } // end if

  } // end while

  system("PAUSE"); return 0;

}
