Monthly Budget Program

Nov 10, 2013 at 10:34pm
My goal is to write a monthly budget program where the user is prompted to enter in how much they spent in 10 categories, and the program will compare to what is allotted for as the budget constraints.

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

using namespace std;

struct Budget  //declare a global type
{
    double housing;
    double utilities;
    double household_exp;
    double transportation;
    double food;
    double medical;
    double insurance;
    double entertainment;
    double clothing;
    double misc;
};

Budget set_budget()
{
    Budget set = {500.00, 150.00, 65.00, 50.00, 250.00, 30.00, 100.00,
        150.00, 75.00, 50.00};
    
    return(set);
}


Budget get_spent() //returns a budget spent structure
{
    Budget spent;
    
    cout<<"Enter in Housing Expense: ";
    cin>>spent.housing;
    cout<<"Enter in Utilities Expense: ";
    cin>>spent.utilities;
    cout<<"Enter in Household Expenses: ";
    cin>>spent.household_exp;
    cout<<"Enter in Transportation Expense: ";
    cin>>spent.transportation;
    cout<<"Enter in Food Expense: ";
    cin>>spent.food;
    cout<<"Enter in Medical Expense: ";
    cin>>spent.medical;
    cout<<"Enter in Insurance Expense: ";
    cin>>spent.insurance;
    cout<<"Enter in Entertainment Expense: ";
    cin>>spent.entertainment;
    cout<<"Enter in Clothing Expense: ";
    cin>>spent.clothing;
    cout<<"Enter in Miscellaneous Expenses: ";
    cin>>spent.misc;
    
    return spent;
}

Budget calculate_spent()
{
    Budget total;
    
    Budget spent;
    
    Budget fixed;
    
    
    fixed = set_budget();
    spent = get_spent();
    
    total.housing = (fixed.housing - spent.housing);
    total.utilities = (fixed.utilities - spent.utilities);
    total.household_exp = (fixed.household_exp - spent.household_exp);
    total.transportation = (fixed.transportation - spent.transportation);
    total.food = (fixed.food - spent.food);
    total.medical = (fixed.medical - spent.medical);
    total.insurance = (fixed.insurance - spent.insurance);
    total.entertainment = (fixed.entertainment - spent.entertainment);
    total.clothing = (fixed.clothing - spent.clothing);
    total.misc = (fixed.misc - spent.misc);
    
    return(total);
}

void output()
{
    Budget fixed;
    Budget set_budget;
    fixed = set_budget;
    
    
    Budget spent;
    Budget get_spent;
    spent = get_spent;
    
    Budget total;
    Budget calculate_spent;
    total = calculate_spent;
    
    Budget difference = (set_budget, get_spent);
    
    cout<<"Category\t\t"<<"Budgeted\t"<<"Spent\t"<<"Over(-)/Under\n"
    "------------------------------------------------------------\n"
    "Housing\t\t"<<fixed.housing<<"\t"<<spent.housing<<"\t\t\n"
    "Utilities\t\t"<<fixed.utilities<<"\t"<<spent.utilities<<"\t\t\n"
    "Household_Exp\t\t"<<fixed.household_exp<<"\t"<<spent.household_exp<<"\t\t\n"
    "Transportation\t\t"<<fixed.transportation<<"\t"<<spent.transportation<<"\t\t\n"
    "Food\t\t"<<fixed.food<<"\t"<<spent.food<<"\t\t\n"
    "Medical\t\t"<<fixed.medical<<"\t"<<spent.medical<<"\t\t\n"
    "Insurance\t\t"<<fixed.insurance<<"\t"<<spent.insurance<<"\t\t\n"
    "Entertainment\t\t"<<fixed.entertainment<<"\t"<<spent.entertainment<<"\t\t\n"
    "Clothing\t\t"<<fixed.clothing<<"\t"<<spent.clothing<<"\t\t\n"
    "Miscellaneous\t\t"<<fixed.misc<<"\t"<<spent.misc<<"\t\t";
    
    
    
    
    
}


int main()
{
    
    
    set_budget();
    calculate_spent();
    output();
    return 0;
}


My question is. Is it possible to create a total function that shows the total fixed and user budget, and an equation showing the difference between the 2 values (like fixed.housing - spent.housing) and answer will display in a 3rd column.

Thank you for the assistance.
Nov 11, 2013 at 12:21am
Yes, it is possible.
Nov 11, 2013 at 12:23am
How would I go about doing it? I am not entirely sure how to do so, or in which function to place it in.
Nov 11, 2013 at 2:08am
Does not your output function do it already? Just fix how it will be displayed.
Nov 11, 2013 at 2:34am
It does not. The difference function is unused. I am trying to get it to output something.
Nov 11, 2013 at 3:01am
what difference function? could you show me your wanted output sample..

is it like
1
2
Total Fixed         Total Budget          Difference          Answer
1234                1111                    100-99             1
Last edited on Nov 11, 2013 at 3:03am
Nov 11, 2013 at 3:32am
It would be like.
1
2
Total Fixed     Total Budget      Difference
1500              1200                300.


No answer column. The third column would be the difference of the first two columns, whether it be positive or negative.
Nov 11, 2013 at 3:38am
add all the spent and the fixed so you can get the total then subtract
Nov 11, 2013 at 3:49am
I understand that part but what function would be used in the code?
Last edited on Nov 11, 2013 at 3:49am
Nov 11, 2013 at 5:02am
use the output function
Nov 11, 2013 at 5:31pm
I meant what would the equation look like? total = (set_budget - get_spent)?
Nov 11, 2013 at 5:46pm
closed account (N36fSL3A)
You can simplify the process by overloading an operator:

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
struct Budget  //declare a global type
{
    double housing;
    double utilities;
    double household_exp;
    double transportation;
    double food;
    double medical;
    double insurance;
    double entertainment;
    double clothing;
    double misc;

    Budget operator -(const Budget b)
    {
        Budget ret;
        
        ret.housing = housing - b.housing;
        ret.utilities = utilities - b.utilities;
        ret.household_exp = household_exp - household_exp;
        ret.transportation = transportation - b.transportation;
        // Continue on with subtracting....

        return ret;
    }
};


Then you would do this:
1
2
3
4
5
Budget a, b, c;

// Code...

a = b - c;
Last edited on Nov 11, 2013 at 5:48pm
Nov 11, 2013 at 7:31pm
This wouldn't be in addition to what I have correct? It would be modifying a current function already used?
Nov 11, 2013 at 7:42pm
closed account (N36fSL3A)
Just add it to your struct. You don't have to change anything at all.
Nov 11, 2013 at 7:46pm
And the second function gets added where? to the void output? Sorry if I am asking too much. I wanted the program to give me:
A. The fixed budget.
B. The user budget.
C. The difference between the two.
D. The total budget (both fixed and user) and the difference.

I do have A and B. I would assume that the calculate_spent would have given me C but it is not.

I thank you again for the assistance you are giving me.


I attempted to run a quick fix and insert total.housing, etc.... in lines 103-112, but the output is garbage.
Last edited on Nov 11, 2013 at 7:54pm
Nov 11, 2013 at 8:30pm
Adding in this using same format as above:

1
2
3
4
5
6
7
8
9
10
11
12
13
cout<<"Category\t\t"<<"Budgeted\t"<<"Spent\t"<<"Over(-)/Under\n"
    "------------------------------------------------------------\n"
    "Housing\t\t"<<fixed.housing<<"\t"<<spent.housing<<"\t"<<total.housing<<"\t\n"
    "Utilities\t\t"<<fixed.utilities<<"\t"<<spent.utilities<<"\t"<<total.utilities<<"\t\n"
    "Household_Exp\t\t"<<fixed.household_exp<<"\t"<<spent.household_exp<<"\t"<<total.household_exp<<"\t\n"
    "Transportation\t\t"<<fixed.transportation<<"\t"<<spent.transportation<<"\t"<<total.transportation<<"\t\n"
    "Food\t\t"<<fixed.food<<"\t"<<spent.food<<"\t"<<total.food<<"\t\n"
    "Medical\t\t"<<fixed.medical<<"\t"<<spent.medical<<"\t"<<total.medical<<"\t\n"
    "Insurance\t\t"<<fixed.insurance<<"\t"<<spent.insurance<<"\t"<<total.insurance<<"\t\n"
    "Entertainment\t\t"<<fixed.entertainment<<"\t"<<spent.entertainment<<"\t"<<total.entertainment<<"\t\n"
    "Clothing\t\t"<<fixed.clothing<<"\t"<<spent.clothing<<"\t"<<total.clothing<<"\t\n"
    "Miscellaneous\t\t"<<fixed.misc<<"\t"<<spent.misc<<"\t"<<total.misc<<"\t";
    


Yields garbage for the total value. Any reason why?
Topic archived. No new replies allowed.