// Marnisha binti Mustafa Kamal (A20EC0075)
// Woon Zi Jian (A20EC0171)
// SECJ1013 - 01
// 16 Dec 2020

#include <iostream>
#include <iomanip>

using namespace std;

void choice1();
void choice2();
void choice3();

int main(){
    
    int choice; // choice: 1, 2 or 3
    char code; // 'N' will terminate the programme
    
    while (code != 'N'){
    cout << "National Flood Forecasting and Warning System: \n\n";
    cout << "\t 1. River Water Level Advisory \n";
    cout << "\t 2. Rainfall Advisory \n";
    cout << "\t 3. Exit \n\n";
    cout << "Enter your choice either 1, 2 or 3 => ";
    cin >> choice;
    
    if (choice==1){
        choice1();
        cout << "------------------------------------- \n";
        cout << "Press any key to continue. \n";
        cout << "Press 'N' to stop. \n";
        cin >> code;
        cout << "------------------------------------- \n\n";
    }
    
    else if (choice==2){
        choice2();
        cout << "------------------------------------- \n";
        cout << "Press any key to continue. \n";
        cout << "Press 'N' to stop. \n";
        cin >> code;
        cout << "------------------------------------- \n\n";
    }
    
    else if (choice==3){
        choice3();
        return 0;
    }
    
    else{
        cout << "Invalid. \n";
        cout << "Please try again. \n\n";
        code = 'Y';
    }
    }
    
    cout << "Thank you.";
    
    return 0;
}
    
void choice1(){
        
        int d=1000; // d: water density
        float h, p, g=9.80665; // h: water level; p: water pressure; g: gravity
        string location;

        cout << endl << "Please enter your location => ";
        cin >> location;
        cout << "\nEnter the water pressure value in psi => ";
        cin >> p;
        h = p / (d * g); //formula for water level value
        
        cout << "\n\nFlood Forecasting and Warning Information" << endl;
        cout << "-------------------------------------" << endl;
        cout << "a. Location               : " << location << endl;
        cout << "b. Water level value      : " << fixed << setprecision(2) << h << endl;
        
        if (h <= 18.94){
            cout << "c. Status                 : Normal \n";
            cout << "d. Flood possibility      : Flood is impossible \n";
            cout << "e. Response               : Preparedness \n\n";
        }
        
        else if (h >= 18.95 && h <= 19.34){
            cout << "c. Status                 : Alert \n";
            cout << "d. Flood possibility      : Flood is possible \n";
            cout << "e. Response               : Awareness \n\n";
        }
        
        else if (h >= 19.35 && h <= 19.53){
            cout << "c. Status                 : Warning \n";
            cout << "d. Flood possibility      : Flood is threatening \n";
            cout << "e. Response               : Preparedness \n\n";
        }
        
        else{
            cout << "c. Status                 : Danger \n";
            cout << "d. Flood possibility      : Serious flooding expected in low lying areas \n";
            cout << "e. Response               : Evacuation \n\n";
        }
    }
    
void choice2(){
    
        float r1, r2, r3;
        float a; // r1, r2, r3: rainfall value; a: average
        string location;

        cout << endl << "Please enter your location => ";
        cin >> location;
        
        cout << "\nEnter the rainfall value for the first hour (in mm)  => ";
        cin >> r1;
        cout << "\nEnter the rainfall value for the second hour (in mm) => ";
        cin >> r2;
        cout << "\nEnter the rainfall value for the third hour (in mm)  => ";
        cin >> r3;
        a = (r1 + r2 + r3)/3; //formula of average rainfall
        
        cout << "\n\nFlood Forecasting and Warning Information" << endl;
        cout << "-------------------------------------" << endl;
        cout << "a. Location             : " << location << endl;
        cout << "b. Average rainfall     : " << fixed << setprecision(2) << a << endl;
        
        if (a < 7.5){
            cout << "c. Status               : Light \n";
            cout << "d. Flood possibility    : Impossible \n";
            cout << "e. Response             : No restricted outdoor activities \n\n";
        }
        
        else if (a >= 7.5 && a < 15){
            cout << "c. Status               : Heavy \n";
            cout << "d. Flood possibility    : Possible \n";
            cout << "e. Response             : Awareness \n\n";
        }
        
        else if (a >= 15 && a < 30){
            cout << "c. Status               : Intense \n";
            cout << "d. Flood possibility    : Threatening \n";
            cout << "e. Response             : Preparedness \n\n";
        }
        
        else{
            cout << "c. Status               : Torrential \n";
            cout << "d. Flood possibility    : Serious flooding expected in low lying areas \n";
            cout << "e. Response             : Evacuation \n\n";
        }
}

void choice3(){
    cout << "You have decided to exit. \n";
    cout << "Thank you for using this system. \n\n";
}
