#include <iostream>
#include <iomanip>
#include <string>
#include <limits>

using namespace std;

void viewHouse(House housing[], int totalHouse) {
	
	system("cls");
  	cout<<"\n\t\t\t     VIEWING HOUSES" << endl;
  	cout<<"\t\t\t----------------------------" << endl;	
  	
	string lot;
	string propertyName;
	int totalBedrooms;
	int totalBathrooms;
	double price;
	int status; //1 - available, 2 - sold
	string buyerName;  	
  	
  	for(int i=0; i<totalHouse; i++) {
  		
  		House house = housing[i];
  		
  		cout << "\t\t\t House " << i+1 << endl;
  		cout << "\t\t\t Lot: " << house.lot << endl;
  		cout << "\t\t\t Property name: " << house.propertyName << endl;
  		cout << "\t\t\t Total bedrooms: " << house.totalBedrooms << endl;
  		cout << "\t\t\t Total bathrooms: " << house.totalBathrooms << endl;
  		
  		cout << setprecision(2);
		cout << fixed;
  		cout << "\t\t\t Price: RM" << house.price << endl;
  		
  		if (house.status == 1) {
  			cout << "\t\t\t Status: available" << endl;
		} else {
			cout << "\t\t\t Status: not available - already sold" << endl;
		}
		
		cout << endl;
	}
  	
  	system("pause");
	system("cls");
	
}

void buyHouse(House housing[], string buyerName, int totalHouse) {
	
	string houseLot;
	
	system("cls");
  	cout<<"\n\t\t\t     BUYING HOUSE" << endl;
  	cout<<"\t\t\t----------------------------" << endl;
	  
  	for(int i=0; i<totalHouse; i++) {
  		
  		House house = housing[i];
  		
  		cout << "\t\t\t House " << i+1 << endl;
  		cout << "\t\t\t Lot: " << house.lot << endl;
  		cout << "\t\t\t Property name: " << house.propertyName << endl;
  		cout << "\t\t\t Total bedrooms: " << house.totalBedrooms << endl;
  		cout << "\t\t\t Total bathrooms: " << house.totalBathrooms << endl;
  		
  		cout << setprecision(2);
		cout << fixed;
  		cout << "\t\t\t Price: RM" << house.price << endl;
  		
  		if (house.status == 1) {
  			cout << "\t\t\t Status: available" << endl;
		} else {
			cout << "\t\t\t Status: not available - already sold" << endl;
		}
		
		cout << endl;
	}
	
	cout << "\t\t\t Enter lot no: ";
  	cin >> houseLot;
  	
  	cin.clear();
  	cin.ignore(numeric_limits<streamsize>::max(), '\n');
	  
	for(int i=0; i<totalHouse; i++) {
  		
  		House house = housing[i];
  		
  		if ((house.lot).compare(houseLot) == 0) {
  			
  			if (house.status == 1) {
  				
	  			cout << endl;
	  			cout << "\t\t\t House with lot no: " << houseLot << " is sold" << endl;
	  			
	  			//update housing array
	  			housing[i].status = 2;
	  			housing[i].buyerName = buyerName;
	  			
	  			break;
	  			 
	  		} else {
	  			cout << endl;
  				cout << "\t\t\t House with lot no: " << houseLot << " already bought by someone else" << endl;  				
  				
  				break;
  				
			}
		}
	}
  	
  	system("pause");
	system("cls");
	
}

void print(House housing[], string buyerName, int totalHouse) {
	
	system("cls");
  	cout<<"\n\t\t\t     PRINT TRANSACTION" << endl;
  	cout<<"\n\t\t\t       HOUSE BOUGHT" << endl;
  	cout<<"\t\t\t----------------------------" << endl;	
  	
  	int index = 0;
  	
	for(int i=0; i<totalHouse; i++) {
  		
  		House house = housing[i];
  		
  		if ((house.buyerName).compare(buyerName) == 0) {
  			
  			index++;
  			
	  		cout << "\t\t\t House " << index << endl;
	  		cout << "\t\t\t Lot: " << house.lot << endl;
	  		cout << "\t\t\t Property name: " << house.propertyName << endl;
	  		cout << "\t\t\t Total bedrooms: " << house.totalBedrooms << endl;
	  		cout << "\t\t\t Total bathrooms: " << house.totalBathrooms << endl;
	  		
	  		cout << setprecision(2);
			cout << fixed;
	  		cout << "\t\t\t Price: RM" << house.price << endl;  
		  	
			cout << endl;		
		}
	}  	
  	
  	system("pause");
	system("cls");
}
