fork download
  1. // Elaine Torrez CS1A #11 Chapter 11 – Monthly Budget Problem
  2.  
  3. /********************************************************************************************
  4.  *
  5.  * MONTHLY BUDGET REPORT
  6.  *
  7.  * ------------------------------------------------------------------------------------------
  8.  * This program compares a student's actual monthly spending with a predefined budget.
  9.  * In this version, no user input is required. Both the budget amounts and the actual
  10.  * spending amounts are hard-coded into structure variables. The program calculates
  11.  * whether the student is over or under budget in each category, as well as the total
  12.  * amount over/under for the entire month.
  13.  * ------------------------------------------------------------------------------------------
  14.  *
  15.  * INPUT (none – all values are preset inside the program)
  16.  *
  17.  * OUTPUT
  18.  * Difference in each category (over or under)
  19.  * Total difference for the month
  20.  *
  21.  ********************************************************************************************/
  22.  
  23. #include <iostream>
  24. #include <iomanip>
  25. using namespace std;
  26.  
  27. // ----------------------------------------------------------
  28. // Structure holding all budget categories
  29. // ----------------------------------------------------------
  30. struct MonthlyBudget {
  31. float Housing;
  32. float Utilities;
  33. float Household;
  34. float Transportation;
  35. float Food;
  36. float Medical;
  37. float Insurance;
  38. float Entertainment;
  39. float Clothing;
  40. float Misc;
  41. };
  42.  
  43. // Function prototype
  44. void displayReport(const MonthlyBudget &, const MonthlyBudget &);
  45.  
  46. int main()
  47. {
  48. // PREDEFINED MONTHLY BUDGET (given in the problem)
  49. MonthlyBudget budget = {
  50. 500.00, // Housing
  51. 150.00, // Utilities
  52. 65.00, // Household expenses
  53. 50.00, // Transportation
  54. 250.00, // Food
  55. 30.00, // Medical
  56. 100.00, // Insurance
  57. 150.00, // Entertainment
  58. 75.00, // Clothing
  59. 50.00 // Miscellaneous
  60. };
  61.  
  62. // HARD-CODED ACTUAL SPENDING (NO USER INPUT)
  63. MonthlyBudget actual = {
  64. 520.00, // Housing spent
  65. 140.00, // Utilities spent
  66. 80.00, // Household expenses spent
  67. 60.00, // Transportation spent
  68. 230.00, // Food spent
  69. 20.00, // Medical spent
  70. 100.00, // Insurance spent
  71. 200.00, // Entertainment spent
  72. 70.00, // Clothing spent
  73. 40.00 // Miscellaneous spent
  74. };
  75.  
  76. displayReport(budget, actual); // OUTPUT
  77.  
  78. return 0;
  79. }
  80.  
  81. // ----------------------------------------------------------
  82. // Function displays over/under for each category and total
  83. // ----------------------------------------------------------
  84. void displayReport(const MonthlyBudget &b, const MonthlyBudget &a)
  85. {
  86. cout << fixed << setprecision(2);
  87.  
  88. cout << "\n\nMONTHLY BUDGET REPORT\n";
  89. cout << "---------------------------------------------------\n";
  90.  
  91. float totalBudget =
  92. b.Housing + b.Utilities + b.Household + b.Transportation +
  93. b.Food + b.Medical + b.Insurance + b.Entertainment +
  94. b.Clothing + b.Misc;
  95.  
  96. float totalActual =
  97. a.Housing + a.Utilities + a.Household + a.Transportation +
  98. a.Food + a.Medical + a.Insurance + a.Entertainment +
  99. a.Clothing + a.Misc;
  100.  
  101. cout << "Housing : " << a.Housing - b.Housing << endl;
  102. cout << "Utilities : " << a.Utilities - b.Utilities << endl;
  103. cout << "Household : " << a.Household - b.Household << endl;
  104. cout << "Transportation : " << a.Transportation - b.Transportation << endl;
  105. cout << "Food : " << a.Food - b.Food << endl;
  106. cout << "Medical : " << a.Medical - b.Medical << endl;
  107. cout << "Insurance : " << a.Insurance - b.Insurance << endl;
  108. cout << "Entertainment : " << a.Entertainment - b.Entertainment << endl;
  109. cout << "Clothing : " << a.Clothing - b.Clothing << endl;
  110. cout << "Miscellaneous : " << a.Misc - b.Misc << endl;
  111.  
  112. cout << "\nTOTAL difference : " << totalActual - totalBudget << endl;
  113. }
  114.  
Success #stdin #stdout 0.01s 5272KB
stdin
500
150
65
50
250
30
100
150
75
50
stdout

MONTHLY BUDGET REPORT
---------------------------------------------------
Housing          : 20.00
Utilities        : -10.00
Household        : 15.00
Transportation   : 10.00
Food             : -20.00
Medical          : -10.00
Insurance        : 0.00
Entertainment    : 50.00
Clothing         : -5.00
Miscellaneous    : -10.00

TOTAL difference : 40.00