//Assignment 2
//Gui Yu Xuan A20EC0039 16/12/2020
//Nurzarifah Binti Azizan A20EC0127 16/12/2020 

/* This program helps the department to compute the flood warning information.*/

//header file
#include<iostream>
#include<iomanip>

using namespace std;

void choices1(); //choice for River Water Level Advisory
void choices2(); //choice for Rainfall Advisory
void choices3(); //choice for Exit

int main() //begin a function
{ 
	int number; //declare variable number
	
	//starting a while loop to evaluate the variable number
	while(number!=3){ 
	cout<<"National Flood Forecasting and Warning System: "<<endl; //display a prompt
	cout<<endl; //starting a new line
	cout<<"\t1. River Water Level Advisory"<<endl; //display a prompt
	cout<<"\t2. Rainfall Advisory"<<endl; //display a prompt
	cout<<"\t3. Exit"<<endl; //display a prompt
	cout<<endl; //starting a new line
	cout<<"Enter your choice either 1, 2 or 3 => "; //display a prompt
	cin>>number; //input a value into variable number
	cout<<endl;  //starting a new line
	
	//starting a if statement to evaluate the variable number 
	if(number==1){
		
		choices1(); //calling a function for choosing choices1
		cout<<"-------------------------------------------"<<endl; //create a dotted line
		cout<<endl; //starting a new line
		
	}else if(number==2){
		
		choices2(); //calling a function for choosing choices2
		cout<<"-------------------------------------------"<<endl; //create a dotted line
		cout<<endl; //starting a new line
		
	}else if(number==3){
		
		choices3(); //calling a function for choosing choices3
		cout<<"-------------------------------------------"<<endl; //create a dotted line
		cout<<endl; //starting a new line
		
	}else{
		cout<<"Error!"<<endl; //display a prompt
		cout<<"Please try again!"<<endl<<endl; //display a prompt
	} //end of if statement
	} //end of while loop
} //end of a function

void choices1() //begin a function 
{
	//declare variables
	string location; //user's location
	float p,h,g=9.80665; //p=water pressure in psi, h=water level in meter, g=specific gravity
	int d=1000; //d=water density
	
	cout<<"Enter the area of location => "; //display a prompt
	cin>>location; //input place into variable location 
	cout<<endl; //starting a new line
	cout<<"Enter the water pressure value in psi => "; //display a prompt
	cin>>p; //input a value into variable p
	cout<<endl; //starting a new line
	cout<<"Flood Forecasting and Warning Information"<<endl; //display a prompt
    cout<<"-----------------------------------------"<<endl; //create a dotted line 
    cout<<"a. Location          : "<<location<<endl; //display a prompt
    h=p/(d*g); //equation for calculating water level in meter
    cout<<"b. Water level value : "<<setprecision(2)<<fixed<<h<<endl; //set the decimal points of h to 4 and display a prompt
    
	//starting a if statement to evaluate the variable h
	if(h<18.94){
        
		cout<<"c. Status            : Normal"<<endl; //display a prompt
        cout<<"d. Flood possiblity  : Flood is impossible"<<endl; //display a prompt
        cout<<"e. Response          : No restricted outdoor activities"<<endl; //display a prompt
        
    }else if(h>=18.95 && h<=19.34){
        
		cout<<"c. Status            : Alert"<<endl; //display a prompt
        cout<<"d. Flood possiblity  : Flood is possible"<<endl; //display a prompt
        cout<<"e. Response          : Awareness"<<endl; //display a prompt
        
    }else if(h>=19.35 && h<=19.53){
       
	    cout<<"c. Status            : Warning"<<endl;
        cout<<"d. Flood possiblity  : Flood is threatening"<<endl; //display a prompt
        cout<<"e. Response          : Preparedness"<<endl; //display a prompt
        
    }else {
       
	    cout<<"c. Status            : Danger"<<endl; //display a prompt
        cout<<"d. Flood possiblity  : Serious flooding expected in low lying areas"<<endl; //display a prompt
        cout<<"e. Response          : Evacuation"<<endl; //display a prompt
        
    } //end of if statement
} //end of a function

void choices2() //begin a function
{
	//declare variables
	string location; //user's location
	float rv,arv,sum; //rv=rainfall value, arv=average rainfall value, sum=sum of rainfall value
	int i; //counter
	
	cout<<"Enter the area of location => "; //display a prompt
	cin>>location; //input a place into variable location
	cout<<endl; //starting a new line
	
	i=1,sum=0; //define the variable i as 1 and sum as 0 
	//starting a while statement to calculate the rainfall value for every hour for 3 hours
	while(i<4) 
	{
		cout<<"Enter the rainfall value (in mm) => "; //display a prompt
		cin>>rv; //input a value into variable rv
		sum=sum+rv; //calculate the sum for the rainfall value
		i++; //increase counter as one
	} //end of while statement
	cout<<endl; //starting a new line
	cout<<"Flood Forecasting and Warning Information"<<endl; //display a prompt
    cout<<"-----------------------------------------"<<endl; //create a dotted line
    cout<<"a. Location         : "<<location<<endl; //display a prompt
    arv=sum/3; //calculate the average rainfall value
    cout<<"b. Average Rainfall : "<<setprecision(2)<<fixed<<arv<<endl; //display a prompt
    //starting if statement to evaluate the variable arv
	if(arv<7.5){
        cout<<"c. Status           : Light"<<endl; //display a prompt
        cout<<"d. Flood possiblity : Flood is impossible"<<endl; //display a prompt
        cout<<"e. Response         : No restricted outdoor activities"<<endl; //display a prompt
    }else if(arv<15){
        cout<<"c. Status           : Heavy"<<endl; //display a prompt
        cout<<"d. Flood possiblity : Flood is possible"<<endl; //display a prompt
        cout<<"e. Response         : Awareness"<<endl; //display a prompt
    }else if(arv<30){
        cout<<"c. Status           : Intense"<<endl; //display a prompt
        cout<<"d. Flood possiblity : Flood is threatening"<<endl; //display a prompt
        cout<<"e. Response         : Preparedness"<<endl; //display a prompt
    }else {
        cout<<"c. Status           : Torrential"<<endl; //display a prompt
        cout<<"d. Flood possiblity : Serious flooding expected in low lying areas"<<endl; //display a prompt
        cout<<"e. Response         : Evacuation"<<endl; //display a prompt
    } //end of if statement
} //end of a function

void choices3() //begin a function
{
	cout<<"You have decided to exit."<<endl<<endl; //display a prompt
	cout<<"Thank you for using this system."<<endl; //display a prompt
} //end of a function
