function call missing argument

Hello all,

We just started going into classes for my C++ class. Everything looks right but the error is saying i'm missing an argument in my getspending call.

Heres the code:
1
2
3
4
5
6
7
8
9
10
for (int i; i < 0; i++)
		{
	cout << members[i].getfirst << " "<< members[i].getlast << endl;

	cout << "member ID: " << members[i].getmem << endl;

        cout << "They have purchased " << members[i].getbooks << " books" << endl;

	cout << "$" << members[i].getspending << endl;
		}


Heres my get spending function:
1
2
3
4
double memberType::getspending()
{
	return spent;
}


what argument am I missing?
Last edited on
To call a function, you have to use parenthesis:

ie:

 
members[i].getbooks()


Note the empty parenthesis at the end.
Last edited on
do you need something else?
If the function takes any parameters, you'll have to supply those as well. But since all these functions are getters, I'm assuming they don't take parameters.
oh wow, sorry, it didn't show any replies. yea, this is a getter function thats supposed to output the spent variable. and I'll try that disch.

Edit: yea adding parenthesis didn't help.

heres my entire main
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
#include <iostream>
#include "functions.h"

using namespace std;

int main()
{
	bool found = false;
	int search = 0;
	string firstn, lastn, IDmem;
	int purchasedbooks, control = 0, ndcontrol = 0;
	double moneyspent;
	memberType members[5];

	cout << "Press 1 to add members, 2 to modify existing members, and 3 to display members: " << endl;
	cin >> control;

	if (control == 1)
	{

		for (int i; i < 0; i++)
		{
			cout << "Members Firstname: ";
			cin >> firstn;
			members[i].setfirst(firstn);
			cout << endl;

			cout << "Members Lastname: ";
			cin >> lastn;
			members[i].setlast(lastn);
			cout << endl;

			cout << "Members ID: ";
			cin >> IDmem;
			members[i].setmem(IDmem);
			cout << endl;

			cout << "Number of books purchased: ";
			cin >> purchasedbooks;
			members[i].setbooks(purchasedbooks);
			cout << endl;

			cout << "Amount of money spent: ";
			cin >> moneyspent;
			members[i].setspending(moneyspent);
			cout << endl;
		}
	}

	else if (control == 2)
	{
		cout << "What member would you like to modify?" << endl;
		cin >> firstn;

		while (search < 5 && !found)
		{
			if (members[search].getfirst() = firstn)
			{
				found = true;
			}

			else
			{
				search++;
			}
		}

		if (found)
		{
			cout << "Members Firstname: ";
			cin >> firstn;
			members[search].setfirst(firstn);
			cout << endl;

			cout << "Members Lastname: ";
			cin >> lastn;
			members[search].setlast(lastn);
			cout << endl;

			cout << "Members ID: ";
			cin >> IDmem;
			members[search].setmem(IDmem);
			cout << endl;

			cout << "Number of books purchased: ";
			cin >> purchasedbooks;
			members[search].setbooks(purchasedbooks);
			cout << endl;

			cout << "Amount of money spent: ";
			cin >> moneyspent;
			members[search].setspending(moneyspent);
			cout << endl;
		}

	}

	else if (control == 3)
	{
		for (int i; i < 0; i++)
		{
			cout << members[i].getfirst() << " "<< members[i].getlast() << endl;

			cout << "member ID: " << members[i].getmem() << endl;

			cout << "They have purchased " << members[i].getbooks() << " books" << endl;

			cout << "$" << members[i].getspending() << endl;
		}
	}

	else
	{
		system("pause");
		return 0;
	}
}


Edit:

The goal of this is to input the values of the array. Then give the user the power to modify any values they like. Finally to output the values. I would normally do this with a struct, but since we're learning about classes, our teacher wants us to use a class for this.

2nd Edit:

Well this is odd, yesterday it was compiling just fine. Now its throwing the above errors when it complies.

3rd Edit:

updated the code. Now when I compile it, its having trouble with the second option, the one to edit the values. I'm trying to compare the value in there with one inputted by the user.

heres the error:

c:\users\matt\documents\visual studio 2013\projects\ch 10 lab\ch 10 lab\main.cpp(57): error C2451: conditional expression of type 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

4th Edit:

I see what I was doing wrong, that line it was having trouble with was an assignment operator. Woopsie. fixed that in my code and I was good to go. no more errors.
Last edited on
Topic archived. No new replies allowed.