Monthly Budget

Why is MonthlyBudget set_budget not displaying the numbers?

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
#include <iostream>
#include <iomanip>

using namespace std;

struct MonthlyBudget
{
double housing, utilities, household, transportation, 
       food, medical, insurance, entertainment, clothing, 
       misc;
       
       MonthlyBudget set_budget()
       {
              MonthlyBudget set = {500.00, 150.00, 65.00, 50.00, 250.00, 30.00, 100.00, 
              150.00, 75.00, 50.00};
    
              return(set);
       }
};

void getBudget(MonthlyBudget&);
void showBudget(MonthlyBudget);

int main ()
{
MonthlyBudget spent;   

getBudget(spent);
showBudget(spent);

cout << "\n\n\n";

system ("pause"); 
return 0;
}
void getBudget(MonthlyBudget &spent)
{
            cout << "Enter the housing expense: ";
            cin >> spent.housing;

            cout << "\nEnter the utilities expense: ";
            cin >> spent.utilities;
            
            cout << "\nEnter the household expense: ";
            cin >> spent.household;

            cout << "\nEnter the transportation expense: ";
            cin >> spent.transportation;
            
            cout << "\nEnter the food expense: ";
            cin >> spent.food;
            
            cout << "\nEnter the medical expense: ";
            cin >> spent.medical;
            
            cout << "\nEnter the insurance expense: ";
            cin >> spent.insurance;
            
            cout << "\nEnter the entertainment expense: ";
            cin >> spent.entertainment;
            
            cout << "\nEnter the clothing expense: ";
            cin >> spent.clothing;
            
            cout << "\nEnter the miscellaneous expense: ";
            cin >> spent.misc;
                  
            cout << "\n\n";
}
void showBudget(MonthlyBudget spent)
{
    MonthlyBudget fix;
    MonthlyBudget set_budget;
    fix = set_budget;
    
    cout << fixed << showpoint << setprecision(2);
    
    cout << "\n\nHousing" << "\t\t\t$" << fix.housing << "\t$" << spent.housing << "\n";
	cout << "Utilities" << "\t\t$" << fix.utilities << "\t$" << spent.utilities << "\n";
	cout << "Household Expenses" << "\t$" << fix.household << "\t$" << spent.household << "\n";
	cout << "Transportation" << "\t\t$" << fix.transportation << "\t$" << spent.transportation << "\n";
	cout << "Food" << "\t\t\t$" << fix.food << "\t$" << spent.food << "\n";
	cout << "Medical" << "\t\t\t$" << fix.medical << "\t$" << spent.medical << "\n";
	cout << "Insurance" << "\t\t$" << fix.insurance << "\t$" << spent.insurance << "\n"; 
	cout << "Entertainment" << "\t\t$" << fix.entertainment << "\t$" << spent.entertainment << "\n";
	cout << "Clothing" << "\t\t$" << fix.clothing << "\t$" << spent.clothing << "\n";
    cout << "Miscellaneous" << "\t\t$" << fix.misc << "\t$" << spent.misc << "\n"; 
}
Okay, to be more specific, rather getting 500 to 75, I get 0's in fix.housing to fix.misc and don't know why.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
MonthlyBudget fix;
MonthlyBudget set_budget;
// now you've created 2 structs of type MonthlyBudget. Both with all variables uninitialized
fix = set_budget; // This doesn't call your method set_budget()
// All you do is copy all those uninitialized variables from the struct named "set_budget" to your struct "fix".
// try something like this:

fix = set_budget.set_budget(); // This now calls the set-budget() method and returns 
// (yet another) struct of type MonthlyBudget

// To make it a bit nicer (not the best possible way but I don't wanna change your whole 
// "set_budget()" method now

// just write: 
MonthlyBudget fix;
fix = fix.set_budget();


This is still terrible code but it works as intended
Thanks. Really, the set_budget.set_budget was needed.

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
#include <iostream>
#include <iomanip>

using namespace std;

struct MonthlyBudget
{
double housing, utilities, household, transportation, 
       food, medical, insurance, entertainment, clothing, 
       misc;
       
       MonthlyBudget set_budget()
       {
              MonthlyBudget set = {500.00, 150.00, 65.00, 50.00, 250.00, 30.00, 
              100.00, 150.00, 75.00, 50.00};
              
              return(set);
       }
};

void getBudget(MonthlyBudget&);
void showBudget(MonthlyBudget);

int main ()
{
MonthlyBudget spent;   

getBudget(spent);
showBudget(spent);

cout << "\n\n\n";

system ("pause"); 
return 0;
}
void getBudget(MonthlyBudget &spent)
{
            cout << "Enter the housing expense: ";
            cin >> spent.housing;
            
            while(spent.housing < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.housing;
                 }

            cout << "\nEnter the utilities expense: ";
            cin >> spent.utilities;
            
            while(spent.utilities < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.utilities;
                 }
            
            cout << "\nEnter the household expense: ";
            cin >> spent.household;
            
            while(spent.household < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.household;
                 }

            cout << "\nEnter the transportation expense: ";
            cin >> spent.transportation;
            
            while(spent.transportation < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.transportation;
                 }
            
            cout << "\nEnter the food expense: ";
            cin >> spent.food;
            
            while(spent.food < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.food;
                 }
            
            cout << "\nEnter the medical expense: ";
            cin >> spent.medical;

            while(spent.medical < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.medical;
                 }
            
            cout << "\nEnter the insurance expense: ";
            cin >> spent.insurance;
            
            while(spent.insurance < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.insurance;
                 }
            
            cout << "\nEnter the entertainment expense: ";
            cin >> spent.entertainment;
            
            while(spent.entertainment < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.entertainment;
                 }
            
            cout << "\nEnter the clothing expense: ";
            cin >> spent.clothing;
            
            while(spent.clothing < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.clothing;
                 }
            
            cout << "\nEnter the miscellaneous expense: ";
            cin >> spent.misc;
            
            while(spent.misc < 0)
                 {
                      cout << "\nInvalid Input. The expense can not be lower than 0: ";
                      cin >> spent.misc;
                 }
                  
            cout << "\n\n";
}
void showBudget(MonthlyBudget spent)
{
    double housing, utilities, household, transportation, 
           food, medical, insurance, entertainment, clothing, 
           misc;
       
    MonthlyBudget set_budget;
    MonthlyBudget fix;
    fix = set_budget.set_budget();
    
    housing = fix.housing - spent.housing;
    utilities = fix.utilities - spent.utilities;
    household = fix.household - spent.household;
    transportation = fix.transportation - spent.transportation;
    food = fix.food - spent.food;
    medical = fix.medical - spent.medical;
    insurance = fix.insurance - spent.insurance;
    entertainment = fix.entertainment - spent.entertainment;
    clothing = fix.clothing - spent.clothing;
    misc = fix.misc - spent.misc;
    
    cout << fixed << showpoint << setprecision(2);
    
    cout << "\n\n\t\t\tSET EXPENSE\tSPENT\t\tDIFFERENCE";
    
    cout << "\n\nHousing" << "\t\t\t$" << fix.housing << "\t\t$" << spent.housing << "\t\t$" << housing << "\n";
	cout << "Utilities" << "\t\t$" << fix.utilities << "\t\t$" << spent.utilities << "\t\t$" << utilities << "\n";
	cout << "Household Expenses" << "\t$" << fix.household << "\t\t$" << spent.household << "\t\t$" << household << "\n";
	cout << "Transportation" << "\t\t$" << fix.transportation << "\t\t$" << spent.transportation << "\t\t$" << transportation << "\n";
	cout << "Food" << "\t\t\t$" << fix.food << "\t\t$" << spent.food << "\t\t$" << food << "\n";
	cout << "Medical" << "\t\t\t$" << fix.medical << "\t\t$" << spent.medical << "\t\t$" << medical << "\n";
	cout << "Insurance" << "\t\t$" << fix.insurance << "\t\t$" << spent.insurance << "\t\t$" << insurance << "\n"; 
	cout << "Entertainment" << "\t\t$" << fix.entertainment << "\t\t$" << spent.entertainment << "\t\t$" << entertainment << "\n";
	cout << "Clothing" << "\t\t$" << fix.clothing << "\t\t$" << spent.clothing << "\t\t$" << clothing << "\n";
    cout << "Miscellaneous" << "\t\t$" << fix.misc << "\t\t$" << spent.misc << "\t\t$" << misc << "\n"; 
}
Topic archived. No new replies allowed.