Trouble Reading In Values

It seems that I'm having trouble reading values into my struct elements...it's probably a beginner's error, easy to fix, but I can't seem to figure it out. Something to do with using 'cin' to read the values? Any help would be appreciated!

The program is for getExpenses to read in values entered by the user. The issue is in lines 26-36(I would think), and the rest is included for context.
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
#include <iostream>
using namespace std;

struct MonthlyBudget{
	double housing,
		utilities,
		medical,
                misc;

	MonthlyBudget(double rent=0.0, double util=0.0, double med=0.0,
				  double insur=0.0, double mis=0.0)
	{ housing=rent;
	  utilities=util;
	  medical=med;
	  misc=mis; }	
};

void getExpenses(const MonthlyBudget&);

int main(){
        MonthlyBudget actual;
        getExpenses(actual);
        return 0;
}

void getExpenses(const MonthlyBudget& expense){
    cout << "Enter actual monthly expenditures for each budget category\n\n";
    cout << "Rent/mortgage:\t";
    cin >> expense.housing;
    cout << "Utilities:\t";
    cin >> expense.utilities;
    cout << "Medical:\t\t";
    cin >> expense.medical;
    cout << "Miscellaneous:\t";
    cin >> expense.misc;
}
Last edited on
In getExpenses you have a reference to a const object so you are not allowed to manipulate any of the members of expense. It should work if you just remove the const.
Okay, that worked. Thought I tried that already <.< Thanks Peter87
Topic archived. No new replies allowed.