// NIK SYAHDINA ZULAIKHA BINTI BADRUL HISHAM A20EC0108 SECJ1013-SECTION 01
// LEE JIA YEE A20EC0063 SECJ1013-SECTION 01 
// DATE : 19/12/2020

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
# define WATER_DENSITY 1000 
# define SPECIFIC_GRAVITY 9.80665 

void River_Water_Level_Advisory(char[20],double&);
void Rainfall_Advisory(char[20],double&);
double wl(double&);                                 //wl = waterlevel
double arg(double&);                               //arg = average

int main()
{
	int num;
	char val [20];
	double water_level;
	double num1,num2,sum,average;
	string s,fp,r;          //s=status, fp=flood_possibility, r=response;
	
	do{
		cout<<"\nNational Flood Forecasting and Warning System:\n\n";
	 	cout<<"      1. River Water Level Advisory\n";
		cout<<"      2. Rainfall Advisory\n";
		cout<<"      3. Exit\n\n";
		cout<<"Enter your choice either 1, 2 or 3 => ";
		cin>>num; 
		
		if (num==1)
		{
			River_Water_Level_Advisory(val,num1);
			
			cout<<"\n\nFlood Forecasting and Warning Information\n\n";
			cout<<"-------------------------------------\n\n";
			cout<<"a. Location          : "<<val<<endl;
			cout<<"b. Water level value : "<<setprecision(4)<<wl(num1)<<endl; 
			water_level=wl(num1);                                               // water_level value in meters
			
			if (water_level<18.95)
			{
				s="Normal";
				fp="Flood is impossible";
				r="No restricted outdoor activities";
			}
			else if ((water_level>=18.95)&&(water_level<19.35))
			{
				s="Alert";
				fp="Flooding is possible";
				r="Awareness";
			}
			else if ((water_level>=19.35)&&(water_level<=19.53))
			{
				s="Warning";
				fp="Flooding is threatening";
				r="Preparedness";
			}
			else
			{
				s="Danger";
				fp="Serious flooding expected in low lying areas";
				r="Evacuation";
			}
	
			
			cout<<"c. Status            : "<<s<<endl;
			cout<<"d. Flood possibility : "<<fp<<endl;
			cout<<"e. Response          : "<<r<<endl;
	    }
		else if (num==2)
		{
			Rainfall_Advisory(val,sum);
		                                                    
			cout<<"\n\n\nFlood Forecasting and Warning Information\n\n";
			cout<<"-------------------------------------\n\n";
			cout<<"a. Location          : "<<val<<endl;
			cout<<"b. Average Rainfall  : "<<setprecision(4)<<arg(sum)<<endl;
			average=arg(sum);                                                  // rainfall_value in mm
			
			if (average<7.5)
	    	{
				s="Light";
			 	fp="Flood is impossible";
				r="No restricted outdoor activities";
			}
			else if(average<15)
			{
				s="Heavy";
				fp="Flooding is possible";
				r="Awareness";
			}
			else if(average<30)
			{
				s="Intense";
				fp="Flooding is threatening";
				r="Preparedness";
			}
			else
			{
				s="Torrential";
				fp="Serious flooding expected in low lying areas";
				r="Evacuation";
			}
			
			cout<<"c. Status            : "<<s<<endl;
			cout<<"d. Flood possibility : "<<fp<<endl;
			cout<<"e. Response          : "<<r<<endl;
		}
		else if (num==3)
			continue;
			
		else
		{
			cout<<"Sorry! You choose the wrong number\n";
		}
		
	}while (num!=3);
	
	cout<<"You have decided to exit.\n";
	cout<<"Thank you for using this system.\n";
	
	return 0; 
}

void River_Water_Level_Advisory(char val[20],double& num1)
{
	
	cout<<"\nEnter the area of location => ";
	cin.ignore();
	cin.getline(val,20);
	cout<<" \nEnter the water pressure value in psi => ";
	cin>>num1;
	
}

double wl(double& num1)
{
	double h,p=num1;
	h = p / ( WATER_DENSITY * SPECIFIC_GRAVITY );
	return h;
}


void Rainfall_Advisory(char val[20], double& sum)
{
	int count,num;
	cout<<"\nEnter the area of location => ";
	cin.ignore();
	cin.getline(val,20);
	sum=0;
	for(count=0;count<3;count++)
	{
		cout<<"\nEnter the rainfall value (in mm) => ";
		cin>>num;
		sum=sum+num;
	}
	
}

double arg(double& sum)
{
	double result;
	result= sum / 3;
	return result;

}


/* Reflection 
	This assignment has strengthen my understanding on chapter 4 Function
	especially in topic "passing by reference". I have understood the proper
	way	to define a function prototype, call and header. I have spent nearly
	haft day to make the program function successfully and hope that next time
	I can improve myself by produce a program within shorter time.  */



