//Adhira B Cs1a CH5 hw
//
/*******************************************************************************
* COMPUTE BUDGET
* _____________________________________________________________________________
* program computes the amount of money owed to expenses and calculates
* the person's budget.
*
* Input
* budget : maximum budget in dollars
* expense : money owed to an expense
* expenses : Total amount of money owed for expenses
*
* Output
* minustotal : Total amount of money left in budget after expenses
*
******************************************************************************/
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
float budget;
float expense; // one expense
float expenses; // total expenses
float total; //OUTPUT, remaining $ in budget
cout << "what is your budget for this month?\n";
cin >> budget;
cout << "enter each of your expenses for the month\n";
cout << "and then enter 0 when finished.\n\n";
cin >> expense;
while (expense != 0)
{
// input validation
if (expense < 0)
{
cout << "please enter a positive expense amount.\n";
}
else
{
expenses += expense;
}
cout << "enter the next expense.\n";
cin >> expense;
}
total = budget - expenses;
cout << fixed << showpoint << setprecision(2);
if (total < 0)
{
cout << "\nthere is $" << abs(total) << " spent over the budget.\n";
}
else if (total > 0)
{
cout << "\nthere is $" << total << " left in the budget.\n";
}
else
{
cout << "no expenses!\n";
}
return 0;
}