//Cameron Pham CS1A Chapter 5, p. 297, #19
//
/******************************************************************************
* ANALYZE BUDGET
* ______________________________________________________________________________
* This program accepts a floating point value for the amount budgeted for a
* Month. A loop then accepts values for every expense for the month. It then
* Evaluates whether the expenses are over or under the budget.
* ______________________________________________________________________________
* INPUT
* Budget // Amount set for budget
* Expenses // Every expense in the month
*
* OUTPUT
* Difference // The amount that is under or over budget
*
*******************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Initialize variables
double budget; // Amount budgeted for the month
double expense; // Individual expense
double totalExpenses = 0; // Running total of all expenses
int numberOfExpenses; // Number of expenses to enter
// Ask the user to enter their monthly budget
cout << "Enter the amount you have budgeted for the month: $";
cin >> budget;
cout << endl;
// Ask the user how many expenses they have
cout << "Enter the number of expenses for the month: ";
cin >> numberOfExpenses;
cout << endl;
// Loop through each expense
for (int count = 1; count <= numberOfExpenses; count++)
{
cout << "Enter expense " << count << ": $";
cin >> expense;
cout << endl;
// Add the current expense to the running total
totalExpenses += expense;
}
// Display the total expenses
cout << fixed << setprecision(2);
cout << endl;
cout << "Total expenses: $" << totalExpenses << endl;
// Determine whether the user is over or under budget
if (totalExpenses > budget)
{
cout << "You are over budget by $"
<< totalExpenses - budget << "." << endl;
}
else if (totalExpenses < budget)
{
cout << "You are under budget by $"
<< budget - totalExpenses << "." << endl;
}
else
{
cout << "You are exactly on budget." << endl;
}
return 0;
}