// Elaine Torrez CS1A #11 Chapter 11 – Monthly Budget Problem
/********************************************************************************************
*
* MONTHLY BUDGET REPORT
*
* ------------------------------------------------------------------------------------------
* This program compares a student's actual monthly spending with a predefined budget.
* In this version, no user input is required. Both the budget amounts and the actual
* spending amounts are hard-coded into structure variables. The program calculates
* whether the student is over or under budget in each category, as well as the total
* amount over/under for the entire month.
* ------------------------------------------------------------------------------------------
*
* INPUT (none – all values are preset inside the program)
*
* OUTPUT
* Difference in each category (over or under)
* Total difference for the month
*
********************************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// ----------------------------------------------------------
// Structure holding all budget categories
// ----------------------------------------------------------
struct MonthlyBudget {
float Housing;
float Utilities;
float Household;
float Transportation;
float Food;
float Medical;
float Insurance;
float Entertainment;
float Clothing;
float Misc;
};
// Function prototype
void displayReport(const MonthlyBudget &, const MonthlyBudget &);
int main()
{
// PREDEFINED MONTHLY BUDGET (given in the problem)
MonthlyBudget budget = {
500.00, // Housing
150.00, // Utilities
65.00, // Household expenses
50.00, // Transportation
250.00, // Food
30.00, // Medical
100.00, // Insurance
150.00, // Entertainment
75.00, // Clothing
50.00 // Miscellaneous
};
// HARD-CODED ACTUAL SPENDING (NO USER INPUT)
MonthlyBudget actual = {
520.00, // Housing spent
140.00, // Utilities spent
80.00, // Household expenses spent
60.00, // Transportation spent
230.00, // Food spent
20.00, // Medical spent
100.00, // Insurance spent
200.00, // Entertainment spent
70.00, // Clothing spent
40.00 // Miscellaneous spent
};
displayReport(budget, actual); // OUTPUT
return 0;
}
// ----------------------------------------------------------
// Function displays over/under for each category and total
// ----------------------------------------------------------
void displayReport(const MonthlyBudget &b, const MonthlyBudget &a)
{
cout << fixed << setprecision(2);
cout << "\n\nMONTHLY BUDGET REPORT\n";
cout << "---------------------------------------------------\n";
float totalBudget =
b.Housing + b.Utilities + b.Household + b.Transportation +
b.Food + b.Medical + b.Insurance + b.Entertainment +
b.Clothing + b.Misc;
float totalActual =
a.Housing + a.Utilities + a.Household + a.Transportation +
a.Food + a.Medical + a.Insurance + a.Entertainment +
a.Clothing + a.Misc;
cout << "Housing : " << a.Housing - b.Housing << endl;
cout << "Utilities : " << a.Utilities - b.Utilities << endl;
cout << "Household : " << a.Household - b.Household << endl;
cout << "Transportation : " << a.Transportation - b.Transportation << endl;
cout << "Food : " << a.Food - b.Food << endl;
cout << "Medical : " << a.Medical - b.Medical << endl;
cout << "Insurance : " << a.Insurance - b.Insurance << endl;
cout << "Entertainment : " << a.Entertainment - b.Entertainment << endl;
cout << "Clothing : " << a.Clothing - b.Clothing << endl;
cout << "Miscellaneous : " << a.Misc - b.Misc << endl;
cout << "\nTOTAL difference : " << totalActual - totalBudget << endl;
}