fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 5 P. 297 #19
  2. //
  3. /******************************************************************************
  4.  *
  5.  * Analyze Budget
  6.  * ___________________________________________________________________________
  7.  * This program will prompt the user to enter an ideal amount for a budget
  8.  * per month. The program then allows the user to enter however many expenses
  9.  * they want until they enter 0 to calculate whether they are under or over
  10.  * their budget
  11.  *
  12.  * Formula that will be used:
  13.  * totalAmount = budget - totalExpenses
  14.  * ___________________________________________________________________________
  15.  * Input
  16.  * budget //Budget user decides to input
  17.  * expenses //Expenses inputted by user
  18.  *
  19.  * Output
  20.  * totalExpenses //Total Amount of Expenses
  21.  *****************************************************************************/
  22. #include <iostream>
  23. using namespace std;
  24. int main()
  25. {
  26. float budget; //INPUT - budget user has decided to enter
  27. float expenses; //INPUT - number of expenses user has made
  28. float totalAmount; //OUTPUT - difference between expenses and budget
  29. float totalExpenses; //OUTPUT - total amount of expenses
  30. //
  31. //Get Inputs
  32. cout << "Enter the amount you have budgeted for this month: $" << endl;
  33. cin >> budget;
  34.  
  35. cout << "Enter your expenses one by one (enter 0 when finished):" << endl;
  36.  
  37. do {
  38. cout << "Expense:$ ";
  39. cin >> expenses;
  40. if (expenses >0)
  41. totalExpenses += expenses;
  42. } while (expenses !=0);
  43.  
  44. cout << "\nTotal expenses: $" << totalExpenses << endl;
  45. //
  46. //
  47. if (totalExpenses > budget)
  48. cout << "You are over budget by $" << totalExpenses - budget << endl;
  49. else if (totalAmount < budget)
  50. cout << "You are under budget by $" << totalExpenses - budget << endl;
  51. else
  52. cout << "You are exactly on budget!" << endl;
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5280KB
stdin
2500
180.79
60.25
15.01
200.05
1256.45
579.12
445.45
0

stdout
Enter the amount you have budgeted for this month: $
Enter your expenses one by one (enter 0 when finished):
Expense:$ Expense:$ Expense:$ Expense:$ Expense:$ Expense:$ Expense:$ Expense:$ 
Total expenses: $2737.12
You are over budget by $237.12