-
Notifications
You must be signed in to change notification settings - Fork 0
/
budget-expense-tracker.cpp
283 lines (169 loc) · 7.49 KB
/
budget-expense-tracker.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;
struct MonthlyBudget
{
double housing
, utilities
, household
, transportation
, food
, medical
, insurance
, entertainment
, clothing
, misc;
// Constructor with default values when arguments are not provided
MonthlyBudget(double rent = 0.0, double util = 0.0, double hh = 0.0,
double trans = 0.0, double fd = 0.0, double med = 0.0,
double insur = 0.0, double fun = 0.0, double cloth = 0.0,
double mis = 0.0
)
{
housing = rent;
utilities = util;
household = hh;
transportation = trans;
food = fd;
medical = med;
insurance = insur;
entertainment = fun;
clothing = cloth;
misc = mis;
}
};
// Function prototypes
void displayBudget(const MonthlyBudget&);
void getExpenses(MonthlyBudget&);
void compareExpenses(const MonthlyBudget&, const MonthlyBudget&);
int main()
{
// Create a MonthlyBudget structure initialized with actual budget figures
MonthlyBudget budget(500,150,65,50,230,30,100,150,75,50);
// Create a MonthlyBudget structure to hold actual expenditures
MonthlyBudget spent;
// Call displayBudget function to display the budgeted amount
displayBudget(budget);
// Call getExpenses function to input and store actual expenditures
getExpenses(spent);
// Call compareExpenses function to compare actual expenditures to budget
compareExpenses(budget,spent);
return 0;
}
/***********************************************************************
* displayBudget *
* This function displays the monthly budgeted amounts in *
* each budget category. *
**********************************************************************/
void displayBudget(const MonthlyBudget &budget)
{
cout << "Here is your monthly budget: \n\n";
cout << "Housing $"<< setw(4) << budget.housing << endl;
cout << "Utilities $"<< setw(4) << budget.utilities << endl;
cout << "Household $"<< setw(4) << budget.household << endl;
cout << "Transportation $"<< setw(4) << budget.transportation << endl;
cout << "Food $"<< setw(4) << budget.food << endl;
cout << "Medical $"<< setw(4) << budget.medical << endl;
cout << "Insurance $"<< setw(4) << budget.insurance << endl;
cout << "Entertainment $"<< setw(4) << budget.entertainment << endl;
cout << "Clothing $"<< setw(4) << budget.clothing << endl;
cout << "Miscellaneous $"<< setw(4) << budget.misc << endl;
}
/***********************************************************************
* getExpenses *
* This function stores the entered values for actual *
* monthly expenditures in each budget category. *
**********************************************************************/
void getExpenses(MonthlyBudget &spent)
{
cout << "\nEnter actual monthly expenditures for each category\n";
cout << "Rent/mortgage: $";
cin >> spent.housing;
cout << "Utilities: $";
cin >> spent.utilities;
cout << "Household: $";
cin >> spent.household;
cout << "Transportation: $";
cin >> spent.transportation;
cout << "Food: $";
cin >> spent.food;
cout << "Medical: $";
cin >> spent. medical;
cout << "Insurance: $";
cin >> spent.insurance;
cout << "Entertainment: $";
cin >> spent.entertainment;
cout << "Clothing: $";
cin >> spent.clothing;
cout << "Miscellaneous: $";
cin >> spent.misc;
}
/***********************************************************************
* compareExpenses *
* This function compares actual expenditures to budgeted *
* amounts in each budget category. *
**********************************************************************/
void compareExpenses(const MonthlyBudget &budget, const MonthlyBudget &spent)
{
double totalBudgeted, // Total monthly budget for all categories
totalSpent, // Total spent in all categories
difference; // Monthly amount over or under budget
// Set output formatting and display table heading
cout << fixed << setprecision(2);
cout << "\n\n Budgeted Spent Difference \n";
cout << "================================================================================================ \n";
// Display budget amount vs. spent amount in each category
cout << "Housing"
<< setw(15) << budget.housing << setw(12) << spent.housing
<< setw(12) << (spent.housing - budget.housing) << endl;
cout << "Utilities"
<< setw(13) << budget.utilities << setw(12) << spent.utilities
<< setw(12) << (spent.utilities - budget.utilities) << endl;
cout << "Household"
<< setw(13) << budget.household << setw(12) << spent.household
<< setw(12) << (spent.household - budget.household) << endl;
cout << "Transportation"
<< setw(8) << budget.transportation << setw(12) << spent.transportation
<< setw(12) << (spent.transportation - budget.transportation) << endl;
cout << "Food"
<< setw(18) << budget.food << setw(12) << spent.food
<< setw(18) << (spent.food - budget.food) << endl;
cout << "Medical"
<< setw(15) << budget.medical << setw(12) << spent.medical
<< setw(15) << (spent.medical - budget.medical) << endl;
cout << "Insurance"
<< setw(13) << budget.insurance << setw(16) << spent.insurance
<< setw(13) << (spent.insurance - budget.insurance) << endl;
cout << "Entertainment"
<< setw(9) << budget.entertainment << setw(12) << spent.entertainment
<< setw(9) << (spent.entertainment - budget.entertainment) << endl;
cout << "Clothing"
<< setw(8) << budget.clothing << setw(12) << spent.clothing
<< setw(12) << (spent.clothing - budget.clothing) << endl;
cout << "Miscellaneous"
<< setw(12) << budget.misc << setw(12) << spent.misc
<< setw(12) << (spent.misc - budget.misc) << endl;
// Compute total amount budgeted, total spent, and the difference
totalBudgeted = budget.housing + budget.utilities + budget.household +
budget.transportation + budget.food + budget.medical +
budget.insurance + budget.entertainment + budget.clothing +
budget.misc;
totalSpent = spent.housing + spent.utilities + spent.household +
spent.transportation + spent.food + spent.medical +
spent.insurance + spent.entertainment + spent.clothing +
spent.misc;
difference = totalBudgeted - totalSpent;
// Display totals and the amount the user was over or under budget this month
cout << "==================================================================\n";
cout << "Total "
<< setw(12) << totalBudgeted << setw(12) << totalSpent
<< setw(12) << difference << endl;
cout << "==================================================================\n";
if (totalBudgeted > totalSpent)
cout << "\nCongratulations! You were $" << difference
<< " under budget this month.\n";
else
cout << "\nYou went $" << -difference << " over your budget this month.\n";
}