/*
________________________________________________________
Group Member: 
              Soh Jun Wei 						- A20EC0151
              Muhammad Naim 					- A20EC0096
              Ethan Leong Yi Thian 				- A20EC0033
________________________________________________________
Section     : 08
Group       : 07
Case Study	: 06
Lecturer	: Dr.Adila Firdaus binti Arbain
									
*/

#include <iostream>
#include <string>
using namespace std;

//	The main() function
int main()
{

    //initialize days
    string dayNames[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};

    // Obtain user input of rain amounts for 7 day
    double rainAmounts[7];
    for (int i = 0; i < 7; ++i)
    {
        cout << "Enter the rain amount for day " << dayNames[i] << ": ";
        cin >> rainAmounts[i];
    }
    cout << "\n";

    // Determine the highest Rain amount, and output it
    double highest = 0;
    for (int i = 0; i < 7; ++i)
        if (highest < rainAmounts[i])
            highest = rainAmounts[i];
    cout << "The highest rain amount is " << highest << ".\n";

    cout << "The highest amount of rain occurred at:";
    for (int i = 0; i < 7; ++i)
        if (rainAmounts[i] == highest)
            cout << " " << dayNames[i];
    cout << ".\n";

    // Determine the average rain amount, and output it
    double sum = 0;
    for (int i = 0; i < 7; i++)
        sum += rainAmounts[i];
    double averageRain = sum / 7.0;
    cout << "Average amount is " << averageRain << ".\n";

    // Determine how many floods had occurred in a week and output it
    double overflow = 0;
    int floodCount = 0;

    for (int i = 0; i < 7; ++i)
    {
        if (rainAmounts[i] + overflow > 230)
        {
            floodCount++;
            overflow = rainAmounts[i] + overflow - 230;
        }
        else
            overflow = 0;
    }

    cout << "The total of flood in the week is " << floodCount << ".\n";

    // Calculate the water levels of the week, including the overflow
    // from previous day(s)
    double waterLevels[7];
    bool isDraught[7] = {};
    double overflow2 = 0;
    for (int i = 0; i < 7; i++)
    {
        waterLevels[i] = overflow2 + rainAmounts[i];
        if (waterLevels[i] - 230 <= 0)
            overflow2 = 0;
        else
            overflow2 = waterLevels[i] - 230;
    }

    //Determine what day are having draught or not having draugh at all
    bool isHaveDraught = false;
    for (int i = 2; i < 7; i++)
        if (waterLevels[i] + waterLevels[i - 1] + waterLevels[i - 2] == 0)
        {
            isDraught[i] = true;
            isDraught[i - 1] = true;
            isDraught[i - 2] = true;
            isHaveDraught = true;
        }

    if (isHaveDraught)
    {
        cout << "Drought occurred at:";
        for (int i = 0; i < 7; i++)
            if (isDraught[i])
                cout << " " << dayNames[i];
        cout << ".\n";
    }
    else
        cout << "No Draught occurred for the week.\n";
}
