//Adding requirements to a22
//Siyang Xia
//100922925
  
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
    // Siyang Xia( 100922925) To determine the house plan 

    // Variables
    double lot_l, // lot length
           house_w, // House Width
           lot_w, // lot width
           house_l, // House Length
           temp = 0, // temperory Value
            total_area =0; // a value that holds the all valid house sizes
           
    double lot_counter =0;
    double valid_lot_size = 0;
    double house_size_entered = 0;
    double house_fits = 0;
    double valid_house_size=0;
    double invalid_house_size =0; 
    double house_fail_lotline=0;
    double house_large=0;
    double house_small=0;
    double area_fit=0;
    double largest_house_area=0;
    double smallest_house_area=0;
    double current_area = 0;
    double current_area1=0; 
           

    cout << "Enter lot width and length: ";
    cin >> lot_w >> lot_l;
    lot_counter++;
    
    // Checking if the lot dimentions are bigger than 0 (zero)
    while (lot_w<=0 || lot_l <=0) {
        cout << "Enter lot width and length - must be positive values: ";
        cin >> lot_w >> lot_l;
        lot_counter++;
    } // end while
    // swapping the variables
    if (lot_w > lot_l) {
        temp = lot_w;
        lot_w = lot_l;
        lot_l = temp;
        // Lot L and Lot W exchanged their value
    } // end if

    cout << "Enter house width and length <0 0 to stop>:";
    cin >> house_w >> house_l;
    if(!(house_w == 0 && house_l ==0))house_size_entered++;
    
    // check if the house width and the house length equal to zero
    while (!(house_w == 0 && house_l == 0)) {
         
        if (!(house_w > 0) || ! (house_l >0)) {
            cout << "Invalid house dimentions - must be positive numbers";
            cout << endl;
            invalid_house_size++;
           
        } else {            
           
            if ((house_w > house_l)) {
                temp = house_w;
                house_w = house_l;
                house_l = temp;
            } // end if 
            valid_house_size++;    
            
            if ((lot_w - house_w) < 4 || (lot_l - house_l) < 4) {
                // i assume that both side of the clearence sum will be 4 or greater
                cout << "House does not fit lot line restriction <min. 2m clearence>" << endl;  
                house_fail_lotline++;            
            } else if ((0.4* (lot_w * lot_l)) <= (house_w*house_l)) {                
                cout << "House is too large <max. 40% of the lot>" << endl;
                house_large++;
            } else if ((0.25 * (lot_w*lot_l)) > (house_w * house_l)) {               
                cout << "House is too small <min. 25% of the lot>" << endl;
                house_small++;
            } else {
               
                cout << "House fit the lot" << endl;
                house_fits++;
                temp=temp+1;//counter for each adding fit house area
                area_fit=house_w * house_l + area_fit; // adding values to calculate ave house area
                total_area = total_area + area_fit;

                current_area = house_w * house_l; // calculating current area              
                if (current_area > largest_house_area) {
                    largest_house_area = current_area;
               }
                 
                else{                    
                    smallest_house_area=current_area;   
                    }           
                } // end if
              
            } // end else
            
         
        
       
        cout << "Enter house width and length <0 0 to stop>:";
        cin >> house_w >> house_l;
        if(!(house_w == 0 && house_l ==0))house_size_entered++; // eliminating the  0 0 user input from counter
       
       
    } // end while

    //output here
    cout << endl <<"Attemps to get valid lot size:" << lot_counter << endl << endl; ;
    cout << "Total number of house size entered:" << house_size_entered << endl;
    cout << "Total number of invalid house size entered:" <<invalid_house_size<<endl; 
    cout << "Total number of valid house size entered:"<< valid_house_size<<endl << endl;;
    cout << "Number of houses that fits lot:"<<house_fits<<endl;
    cout << "Number of houses that fail lot line test:"<<house_fail_lotline<<endl;
    cout << "Number of houses taht are too small:"<<house_small<<endl;
    cout << "Number of houses that are too large:"<<house_large<<endl<<endl;;   
    if(!(house_size_entered == 0)){
        cout << "Percent of House that fits:" <<  ((house_fits * 100)/valid_house_size )<< endl;
        cout << "Percent of House that do not fit lot:"<<((house_fail_lotline+house_large+house_small)*100/valid_house_size)<<endl;
        cout << "Percent of houses that fail lot line test:"<<((house_fail_lotline*100)/valid_house_size)<<endl;
        cout << "Percent of houses that are too small:"<< (house_small*100)/valid_house_size<<endl;
        cout << "Percent of houses that are too large:"<< (house_large*100)/valid_house_size<<endl << endl;
    
        cout << "Average house area:"<<(total_area/temp)<<endl;
        cout << "Largest valid house area:" <<largest_house_area <<endl;
        cout << "Smallest valid house area:"<<smallest_house_area<<endl;
       
    }
    system("PAUSE");

}

