//Assignment 2
//Phang Cheng Yi (A20EC0131)
//Shahril Bin Saiful Bahri (A20EC0144)

//This is a National Flood Forecasting and Warning System
/*This program is used to help the Malaysian Meteorological Department (MetMalaysia) 
  to compute the flood warning information that warn people if the water level is at risk.*/

//header file
#include<iostream>
#include<iomanip>
#include<string>

#define WATER_DENSITY 1000
#define SPECIFIC_GRAVITY 9.80665
using namespace std;

//define function (function prototype)
void choice1(double, double, string&);                         //River Water Level Advisory
void choice2(double&, double&, double&, double&, string&);     //Rainfall Advisory
void choice3();                                                //Exit

//main program
int main(){
	int choice;                                       //declare variables
	double h,p,r1,r2,r3,average;                      //declare variables
	string location;                                  //declare variables
/*where variable h represent water level in meter, varible p represent water pressure in psi,
  and r1,r2,r3 respectively represent rainfall value of each one hour for 3 hours */	
//average is the total sum of 3 rainfall values divided by three.
  
	//display main menu
	while(choice!=3){
	cout<< "National Flood Forecasting and Warning System: "<<endl;
	cout<< "\t1. River Water Level Advisory "<<endl;
	cout<< "\t2. Rainfall Advisory "<<endl;
	cout<< "\t3. Exit "<<endl<<endl;
	cout<< "Enter your choice either 1,2 or 3 => ";
	cin>>choice;                                           //get user's input
	cout<<endl;
	//make decision
    if(choice==1){
		choice1(h,p,location);                         //call function
    }
	else if(choice==2){
		choice2(r1,r2,r3,average,location);                //call function
	}
	else if(choice==3){
		choice3();                                         //call function
	}
	else{
		cout<<"An error occurs. Please try again."<<endl<<endl;    //display an error message
	}                                                      //end of if-else statement
    }                                                      //end of while loop
	return 0;
}                                                          //end the program

//function header
void choice1(double h, double p, string& location){
//void choice1(float& h, float& p, string& location){
	
	cout<<"Enter your location => ";                                  //display a prompt
	cin.ignore();                                                     //ignore the delimiter that stop user to input location
	getline(cin,location);                                            //get user's input
	cout<<endl;
	cout<<"Enter the hydrostatic water pressure value (in psi) => ";  //display another prompt
	cin>>p;                                                           //get user's input
	
	h=(p/(WATER_DENSITY*SPECIFIC_GRAVITY));                                                       //To calculate the water level value
	
	int x = (int) (h * 100);
	h = (double) x / 100;
	
	//display information
	cout<< endl<<endl<<" Flood Forecasting and Warning Information "<<endl;       
	cout<< endl<<" ------------------------------------------ "<<endl<<endl;
	cout<< "a. Location         : "<<location<<endl;
	cout<< "b. Water level value: "<<fixed<<setprecision(2)<<h<<endl;
		
		//make decision
		if(h<18.94){
			cout<<"c. Status           : Normal"<<endl;
			cout<<"d. Flood possibility: Flood is impossible"<<endl;
			cout<<"e. Response         : No restricted outdoor activities "<<endl<<endl;
		}
		else if(h>=18.95 && h<=19.34){
			cout<<"c. Status           : Alert"<<endl;
			cout<<"d. Flood possibility: Flooding is possible"<<endl;
			cout<<"e. Response         : Awareness "<<endl<<endl;
		}
		else if(h>=19.35 && h<=19.53){
			cout<<"c. Status           : Warning"<<endl;
			cout<<"d. Flood possibility: Flooding is threatening"<<endl;
			cout<<"e. Response         : Preparedness "<<endl<<endl;
		}
		else{
			cout<<"c. Status           : Danger"<<endl;
			cout<<"d. Flood possibility: Serious flooding expected in low lying areas"<<endl;
			cout<<"e. Response         : Evacuation "<<endl<<endl;
		}                                                            //end of if-else statement
}                                                                    //end of the function

//function header
void choice2(double& r1, double& r2, double& r3, double& average, string& location){
//void choice2(float& r1, float& r2, float& r3, float& average, string& location){

	cout<<"Enter your location => ";                                 //display a prompt
	cin.ignore();                                                    //ignore the delimiter that stop user to input location
	getline(cin,location);                                           //get user's input
	cout<<endl;
	cout<<"Enter the first rainfall value (in mm) => ";              //display a prompt
	cin>>r1;                                                         //get user's input
	cout<<endl;
	cout<<"Enter the second rainfall value (in mm)=> ";              //display a prompt
	cin>>r2;                                                         //get user's input
	cout<<endl;
	cout<<"Enter the third rainfall value (in mm) => ";              //display a prompt
	cin>>r3;                                                         //get user's input
	
	average=(r1+r2+r3)/3;                                            //To calculate the average of the user's input
	
	//display information
	cout<< endl<<endl<<" Flood Forecasting and Warning Information "<<endl;
	cout<< endl<<" ------------------------------------------ "<<endl<<endl;
	cout<< "a. Location         : "<<location<<endl;
	cout<< "b. Average Rainfall : "<<fixed<<setprecision(2)<<average<<endl;
	
	    //make decision
	    if(average<7.5){
			cout<<"c. Status           : Light"<<endl;
			cout<<"d. Flood possibility: Flood is impossible"<<endl;
			cout<<"e. Response         : No restricted outdoor activities "<<endl<<endl;
		}
	    else if(average<15){
			cout<<"c. Status           : Heavy"<<endl;
			cout<<"d. Flood possibility: Flooding is possible"<<endl;
			cout<<"e. Response         : Awareness "<<endl<<endl;
		}
    	else if(average<30){
			cout<<"c. Status           : Intense"<<endl;
			cout<<"d. Flood possibility: Flooding is threatening"<<endl;
			cout<<"e. Response         : Preparedness "<<endl<<endl;
		}
    	else{
			cout<<"c. Status           : Torrential"<<endl;
			cout<<"d. Flood possibility: Serious flooding expected in low lying areas"<<endl;
			cout<<"e. Response         : Evacuation "<<endl<<endl;
		}                                                  //end of if-else statement
}                                                          //end of the function

//function header
void choice3(){
	cout<<"You have decided to exit."<<endl;               //display a prompt
	cout<<"Thank you for using this system."<<endl;        //display a prompt
}

