//Diego Martinez CSC5 Chapter 5, P.297,#19
/*******************************************************************************
* DISPLAY BUDGET ANALYSIS
* ______________________________________________________________________________
* This program is designed to help a user compare their monthly spending to a
* planned budget.
*
*
* Computation is based on the Formula:
* If the result is positive → you are under budget
* If the result is negative → you are over budget
* If the result is zero → you are exactly on budget
*______________________________________________________________________________
* INPUT
* Budget : (one value)
* Expenses : (multiple values)
* Continue choice : (y or n)
*
* OUTPUT
* Over budget message : user has spent more than the budget
* Under budget message : user has spent less than the budget
* On budget message : user spent exactly the budgeted amount
*
*******************************************************************************/
#include <iostream>
using namespace std;
int main() {
float budget; // Stores the total monthly budget
float expense; // Stores each individual expense
float totalExpenses = 0; // Keeps a running total of all expenses
char choice; // Stores the user’s response (y or n)
// Ask for monthly budget
cout << "Enter your monthly budget: \n";
cin >> budget;
// Loop to enter expenses
do {
cout << "Enter an expense: \n";
cin >> expense;
totalExpenses += expense;
cout << "Do you have another expense to enter? (y/n): \n";
cin >> choice;
} while (choice == 'y' || choice == 'Y');
// Calculate difference
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;
}