#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// OrinTill Qimid CS1A Chapter 4, P. 294, 10
//
// /**************************************************************
// * Calculate monthly budget.
// * 
// * ____________________________________________________________
// * This program will calculate the montly budget.
// * ____________________________________________________________
// * INPUT
// *   Student spending.
// * OUTPUT
// *   Student monthly budget.
// **************************************************************/
 
// Define the MonthlyBudget structure
struct MonthlyBudget {
    double housing = 500.0;
    double utilities = 150.0;
    double householdExpenses = 65.0;
    double transportation = 50.0;
    double food = 250.0;
    double medical = 30.0;
    double insurance = 100.0;
    double entertainment = 150.0;
    double clothing = 75.0;
    double miscellaneous = 50.0;
};

// Function to get user spending for the month
void getSpending(MonthlyBudget &spent) {
    cout << "Enter the amounts spent in each category for the month:\n";
    cout << "Housing: ";
    cin >> spent.housing;
    cout << "Utilities: ";
    cin >> spent.utilities;
    cout << "Household Expenses: ";
    cin >> spent.householdExpenses;
    cout << "Transportation: ";
    cin >> spent.transportation;
    cout << "Food: ";
    cin >> spent.food;
    cout << "Medical: ";
    cin >> spent.medical;
    cout << "Insurance: ";
    cin >> spent.insurance;
    cout << "Entertainment: ";
    cin >> spent.entertainment;
    cout << "Clothing: ";
    cin >> spent.clothing;
    cout << "Miscellaneous: ";
    cin >> spent.miscellaneous;
}

// Function to display the budget report
void displayReport(const MonthlyBudget &budget, const MonthlyBudget &spent) {
    double totalBudget = budget.housing + budget.utilities + budget.householdExpenses +
                         budget.transportation + budget.food + budget.medical +
                         budget.insurance + budget.entertainment + budget.clothing +
                         budget.miscellaneous;

    double totalSpent = spent.housing + spent.utilities + spent.householdExpenses +
                        spent.transportation + spent.food + spent.medical +
                        spent.insurance + spent.entertainment + spent.clothing +
                        spent.miscellaneous;

    double totalDifference = totalBudget - totalSpent;

    cout << fixed << setprecision(2);
    cout << "\nMonthly Budget Report:\n";
    cout << "--------------------------------------------\n";
    cout << "Category          Budgeted    Spent    Over/Under\n";
    cout << "--------------------------------------------\n";

    auto printCategory = [](string category, double budgeted, double spent) {
        double difference = budgeted - spent;
        cout << left << setw(15) << category << " " 
             << setw(10) << budgeted << " " 
             << setw(8) << spent << " " 
             << (difference >= 0 ? "Under " : "Over ") << abs(difference) << endl;
    };

    printCategory("Housing", budget.housing, spent.housing);
    printCategory("Utilities", budget.utilities, spent.utilities);
    printCategory("Household", budget.householdExpenses, spent.householdExpenses);
    printCategory("Transportation", budget.transportation, spent.transportation);
    printCategory("Food", budget.food, spent.food);
    printCategory("Medical", budget.medical, spent.medical);
    printCategory("Insurance", budget.insurance, spent.insurance);
    printCategory("Entertainment", budget.entertainment, spent.entertainment);
    printCategory("Clothing", budget.clothing, spent.clothing);
    printCategory("Miscellaneous", budget.miscellaneous, spent.miscellaneous);

    cout << "--------------------------------------------\n";
    cout << "Total            " << totalBudget << " " << totalSpent << " " 
         << (totalDifference >= 0 ? "Under " : "Over ") << abs(totalDifference) << endl;
}

int main() {
    // Create budget and spending structures
    MonthlyBudget budget;
    MonthlyBudget spent;

    // Get spending details from the user
    getSpending(spent);

    // Display the budget report
    displayReport(budget, spent);

    return 0;
}