//Chong Kah Wei A20EC0027
//Assignment 2
//National Flood Forecasting and Warning System

#include<iostream>
#include<string>
#include <iomanip> 
using namespace std;

//Function declaration
void RequestOne(); 
void RequestTwo();
//Main funcion
int main(){ 
	int x;
	//Provide a menu driven screen for user to make choice of forecast choices, x is the choice input.
	cout<<"National Flood Forecasting and Warning System:\n\n";
	cout<<"\t1. River Water Level Advisory\n\t2. Rainfall Advisory\n\t3. Exit\n\n";
	cout<<"Enter your choice either 1, 2 or 3 => ";
	cin>>x;
	//loop for returning back to the menu driven screen, unless choice 3 is chosen
	while(x!=3){
	if(x==1){	
		RequestOne(); //Go to function RequestOne()
	}	
	else if(x==2){
		RequestTwo(); //Go to function RequesTwo()
	}
	else 
	cout<<"\nError. Please reenter your choice 1, 2 or 3."; //Determine the invalid input	
	//Display again menu driven screen if the choice is not 3
	cout<<"\n\nNational Flood Forecasting and Warning System:\n\n";
	cout<<"\t1. River Water Level Advisory\n\t2. Rainfall Advisory\n\t3. Exit\n\n\n";
	cout<<"Enter your choice either 1, 2 or 3 => ";
	cin>>x;
	}
	if(x==3)
	cout<<"You have decided to exit.\nThank you for using this system."; //System stop when 3 is entered
    return 0;
}
//Sub function for choice 1
void RequestOne(){
	string location;
	int d=1000; // d=water density
	float h,p,g=9.80665;// h=water level in meter, p=water pressure in psi, g=specific gravity
	//Reading the location and water pressure value from the user
	cout<<"\nEnter the area of location => ";
	cin>>location;
	cout<<"\nEnter the water pressure value in psi => ";
	cin>>p;
	cout<<"\n\nFlood Forecasting and Warning Information\n\n";
	cout<<"-------------------------------------\n";
	cout<<"a. Location\t\t: "<<location;
	//Calculating the water level value by using the formula
	h=p/(d*g);
    cout<<"\nb. Water level value\t: "<<fixed<<setprecision(2)<<h; //Display the result h in 2 decimal places
 	cout<<endl;
 	//Determine the water level status, flood possibility and response with different range of h
 	//Display the result
 	  	if(h<=18.94)
 	  	{ cout<<"c. Status\t\t: Normal\n";
 	  	  cout<<"d. Flood possibility\t: Flood is impossible\n";
 	  	  cout<<"e. Response\t\t: No restricted outdoor activities\n";}
 	  	  
 	  	else if(h<=19.34)
		{ cout<<"c. Status\t\t: Alert\n";
 	  	  cout<<"d. Flood possibility\t: Flood is possible\n";
 	  	  cout<<"e. Response\t\t: Awareness\n";}  
 	  	  
 	  	else if(h<=19.53)
		{ cout<<"c. Status\t\t: Warning\n";
 	  	  cout<<"d. Flood possibility\t: Flood is threatening\n";
 	  	  cout<<"e. Response\t\t: Preparedness\n";}    
 	  	  
 	  	else 
		{ cout<<"c. Status\t\t: Danger\n";
 	  	  cout<<"d. Flood possibility\t: Serious flooding expected in low lying areas\n";
 	  	  cout<<"e. Response\t\t: Evacuation\n";}
	
}
//Sub function for choice 2
void RequestTwo(){
	string location; // d=Status, e=Flood posibility, f=Response
	float y1,y2,y3,average;
	/*y1=Rainfall value for 1st hour,
	y2=Rainfall value for 2nd hour, 
	y3=Rainfall value for 3rd hour,
	average=average of 3 rainfall value*/
	//Reading the location and rainfall value from the user
	cout<<"\nEnter the area of location => ";
	cin>>location;
	//The rainfall value is taking for every hour for 3 hours
	cout<<"\nEnter the rainfall value (in mm) => ";
	cin>>y1;
	cout<<"\nEnter the rainfall value (in mm) => ";
	cin>>y2;
	cout<<"\nEnter the rainfall value (in mm) => ";
	cin>>y3;
    cout<<"\n\nFlood Forecasting and Warning Information\n\n";
 	cout<<"--------------------------------------------\n";
 	cout<<"a. Location\t\t: "<<location;
 	//Calculating the average rainfall value using formula
	average=(y1+y2+y3)/3;
 	cout<<"\nb. Average Rainfall\t: "<<fixed<<setprecision(2)<<average;
 	cout<<endl;
 	//Determine the rainfall status, flood possibility and response
 	//Display the result
 	  if(average<7.5)
 	  { cout<<"c. Status\t\t: Light\n";
 	    cout<<"d. Flood possibility\t: Flood is impossible\n";
 	    cout<<"e. Response\t\t: No restricted door activities\n";}
 	  
 	  else if(average<15)
 	  { cout<<"c. Status\t\t: Heavy\n";
 	    cout<<"d. Flood possibility\t: Flood is possible\n";
 	    cout<<"e. Response\t\t: Awareness\n";}
 	  
 	  else if(average<30)
 	  { cout<<"c. Status\t\t: Intense\n";
 	    cout<<"d. Flood possibility\t: Flood is threatening\n";
 	    cout<<"e. Response\t\t: Preparedness\n";}
	  
	  else
	  { cout<<"c. Status\t\t: Torrential\n";
 	    cout<<"d. Flood possibility\t: Serious flooding expected in low lying areas\n";
 	    cout<<"e. Response\t\t: Evacuation\n";}
}


