Jan 30, 2018 at 4:44pm UTC
/*
Program Description: Asks for monthly living expenses. Calculates and
displays the difference between the expenses and budget.
Inputs Needed: Student's monthly expenses.
Processing Required: Calculate budget less expenses.
Outputs Generated: Budget over/under report.
*/
#include <iostream>
#include <iomanip>
using namespace std;
const double Housing = 500, Utilities = 150, Household = 65,
Transportation = 50, Food = 250, Medical = 30, Insurance = 100,
Entertainment = 150, Clothing = 75, Miscellaneous = 50;
double budgetedTotal = Housing + Utilities + Household +
Transportation + Food + Medical + Insurance + Entertainment +
Clothing + Miscellaneous;
//Structure.
struct MonthlyBudget
{
double hous, util, householdExpenses, trans, f, med, ins,
ent, cloth, misc;
};
//Prototype the input validation, etc.
//declare all prototypes here!!!!!
void heading();
double validate();
void getMonthlyBudget(MonthlyBudget &);
void displayMonthlyReport(const MonthlyBudget &);
int main ()
{
MonthlyBudget student;
heading();
getMonthlyBudget(student);
displayMonthlyReport(student);
double overUnder = 0.00;
system ("PAUSE");
return 0;
}
void heading()
{
cout <<"Enter the amount spent in each category for the month:\n\n";
}
double validate()
{
double check;
cin >> check;
if (check < 0)
{
while (check < 0)
{cout << "\tAmounts may not be negative.\n";
cout << "\tEnter a value of 0 or greater.";
cin >> check;
}
}
return check;
}
void getMonthlyBudget(MonthlyBudget &student)
{
cout << fixed << setprecision(2) << setw(24) << "Housing: $";
student.hous = validate();
cout << fixed << setprecision(2) << setw(24) <<"Utilities: $";
student.util = validate();
cout << fixed << setprecision(2) << setw(24) << "Household Expenses: $";
student.householdExpenses = validate();
cout << fixed << setprecision(2) << setw(24) << "Transportation: $";
student.trans = validate();
cout << fixed << setprecision(2) << setw(24) << "Food: $";
student.f = validate();
cout << fixed << setprecision(2)<< setw(24) << "Medical: $";
student.med = validate();
cout << fixed << setprecision(2) << setw(24)<< "Insurance: $";
student.ins = validate();
cout << fixed << setprecision(2) << setw(24)<< "Entertainment: $";
student.ent = validate();
cout << fixed << setprecision(2) << setw(24)<< "Clothing: $";
student.cloth = validate();
cout << fixed << setprecision(2) << setw(24)<< "Miscellaneous: $";
student.misc = validate();
}
//Output
void displayMonthlyReport(MonthlyBudget &student)
{
cout << "\n\nMonthly Over/Under Report:\n\n";
cout << setw(24) << "Housing: $";
cout << Housing - student.hous << endl;
cout << setw(24) << "Utilities: $";
cout << Utilities - student.util << endl;
cout << setw(24) << "Household Expenses: $";
cout << Household - student.householdExpenses << endl;
cout << setw(24) << "Transportation: $";
cout << Transportation - student.trans << endl;
cout << setw(24) << "Food: $";
cout << Food - student.f << endl;
cout << setw(24) << "Medical: $";
cout << Medical - student.med << endl;
cout << setw(24) << "Insurance: $";
cout << Insurance - student.ins << endl;
cout << setw(24) << "Entertainment: $";
cout << Entertainment - student.ent << endl;
cout << setw(24) << "Clothing: $";
cout << Clothing - student.cloth << endl;
cout << setw(24) << "Miscellaneous: $";
cout << Miscellaneous - student.misc << endl;
cout << "----------------------------------------------" << endl;
double spentTotal = student.hous + student.util + student.householdExpenses + student.trans + student.f + student.med
+ student.ins + student.ent + student.cloth + student.misc;
if (spentTotal <= budgetedTotal)
{double under = budgetedTotal - spentTotal;
cout << "Total Monthly Over/Under: $" << under << " under budget." << endl;
}
else
{double over = spentTotal - budgetedTotal;
cout << "Total Monthly Over/Under: $" << over << " over budget." << endl;
}
}
Last edited on Jan 30, 2018 at 4:51pm UTC
Jan 30, 2018 at 4:51pm UTC
Spot the difference:
void displayMonthlyReport(const MonthlyBudget &student);
void displayMonthlyReport(MonthlyBudget &student)