Structure/variable troubles

So I have two montlybudget variables, one being a constant amount and the other available for input. My problem is the achieved variable gets a error reading no appropriate default constructor available. I've spent the last few hours trying to get myself out of the rut. Feel to make some suggestions,but please go easy on me, thanks.
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
#include <iostream>
using namespace std;

struct monthlybudget //monthlybudget structure
{   double housing, utilities, householdExpns, trans, food, medical, insurance, entert, cloth, miscellaneous;
     
    // constructor
	monthlybudget(double house, double util,double houseEx,double tran, double foo, double medic, double insur,double ent, double clo, double misc)
	{ housing = house;
	  utilities = util;
	  householdExpns = houseEx;
      trans = tran;
      food = foo;
      medical = medic;
      insurance = insur;
      entert = ent;
      cloth = clo;
      miscellaneous = misc;
	} 
		void displayData()
		{ cout << housing;
		  cout << utilities;
		  cout << householdExpns;
		  cout << trans;
		  cout << food;
		  cout << medical;
		  cout << insurance;
		  cout << entert;
		  cout << cloth;
		  cout << miscellaneous;
		  cout << "\n";
		}

};
 //prototype
void getcurrent(monthlybudget&);

int main()
{   monthlybudget neededbud(500,150,65,50,250,30,100,150,75,50);
	monthlybudget achievedbud;
	cout << "Please enter your monthly expenses and I will compare them to your budget.\n" << endl;
    
	neededbud.displayData();
    achievedbud.displayData();

	getcurrent(achievedbud);
	system("pause");
	return 0;
}

//Function to get input regarding the actual achieved budget
void getcurrent(monthlybudget &temp)
{ cout << "Enter amount for housing ";
  cin >> temp.housing;
  cout << "Enter amount for utilities ";
  cin >> temp.utilities;
  cout << "Enter amount for household expenses ";
  cin >> temp.householdExpns;
  cout << "Enter amount for transportation ";
  cin >> temp.trans;
  cout << "Enter amount for food ";
  cin >> temp.food;
  cout << "Enter amount for medical ";
  cin >> temp.medical;
  cout << "Enter amount for insurance ";
  cin >> temp.insurance;
  cout << "Enter amount for entertainment ";
  cin >> temp.entert;
  cout << "Enter amount for clothing ";
  cin >> temp.cloth;
  cout << "Enter amount for miscellaneous ";
  cin >> temp.miscellaneous;
}
The problem is here Line 40:
monthlybudget achievedbud;
This is the same as monthlybudget achievedbud(); which is a call to a constructor that takes no arguments (default constructor) and you haven't written one.
So roundabout line 7 you need to add something like:
1
2
3
   // constructors
monthlybudget () {} //empty default constructor
monthlybudget(double house, double util,double houseEx,double tran, double foo, double medic, double insur,double ent, double clo, double misc)
I'm not sure what you're saying. I did some tinkering with your suggestion and got some pretty unattractive output, maybe I'm missing something. I did a little research regarding your response, but a lot of the info seems a little too far over my head.
Last edited on
You do need the default constructor as I suggested otherwise you will not
be able to complie (because that is what the compiler is complaining about).

Now that you can compile and run the program - the unnattractive output is your use of uninitialised variables bcause you do achievedbud.displayData(); before you do getcurrent(achievedbud);.

You need to get the data first before displaing it.

Also your void displayData() function is displaying the data directly one after the other with no spacing or formatting - I assume you are going to add some formatting to sort that out.
Last edited on
Well I was reading and I did find info on default constructors, but it didn't mention anything about empty space. It's cool that it can be applied to a empty default, and yeah I always save formatting for last. Thank you for all your help.
So I pretty much got it to work ,but what I realy want is to have the display function compare the two variables. When I call the display() it reads "does not take 1 arguments", but isnt the argument right? This what I have in my code
1
2
3
4
5
6
7
8
9
10
11
12
void displayInfo(monthlybudget, monthlybudget);//prototypes
Int main()
{monthlybudget neededbudget(500,150,65,50,250,30,100,150,75,50);
  monthlybudget achievedbudget;
  displayInfo(neededbudget);//call for displayData
  displayInfo(achievedbudget);//call for displayData
  return 0;
  }
   // display data function
  void displayInfo(monthlybudget n,monthlybudget a)
    { cout << n.cloth << " " << a.cloth;
     }	 
Well given that on line 1 your displayInfo function prototype shows that it
takes two parameters and the definition on line 10 shows the same.

It means that lines 5 and 6 are incorrect doesn't it !!!!??????

Lines 5 and 6 should be merged into one :
displayInfo(neededbudget, achievedbudget);


Good eye. I do feel a little dumb for making the mistake, but thank you for correcting me.
Topic archived. No new replies allowed.