User Defined Functions Need Help

So I received an error of "type name is not allowed" and I don't know how to fix this....
Here is the code:

1
2
3
4

retrieveData(string Name, double wage, double hours, int exemptions, char Status);
dataCalculations(double wage, double hours, int exemptions, char Status, double grossPay, double ficaTax, double incomeTax, double netPay, double taxWithheld);
sendData(string Name, int ID, double hours, double wage, double ficaTax, double incomeTax, double grossPay, double netPay);


Any suggestions?
Are you trying to call the functions with that code?
yeah
Last edited on
You only put the types of the function arguments when the function is being declared or defined.

When you are calling it, you just pass in the variables.

So, as an example, say I have the following code that defines a function:
1
2
3
4
int foo(int a, string b, int c)
{
    // Does nothing
}


When I call it, I do it like the following:
1
2
3
4
int number1 = 0;
int number2 = 1;
string myString = "abc";
foo(number1, myString, number2);


Does that help?

Note you could also call that function like this:
 
foo(0, "abc", 1);
Last edited on
oh ok i'm going to try that really quick; thanks for help!!
ok lol I fixed that yet now it keeps saying "more than one instance of overloaded function"
I'm going to need to see a lot more of your program to help you with that.

This type of error probably means that there are multiple versions of one of those functions named the same thing with different argument types, and it can't determine which one to use based on your function call.
Here's the whole program:

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

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>

using namespace std;

ifstream infile;
ofstream outfile, errorFile;

void retrieveData(string&, double&, double&, int&, char&);
void dataCalculations(double, double, int, char, double&, double&, double&, double&, double&);
void sendData(string, int&, double, double, double, double, double, double);

int main()
{
	bool clear;
	ifstream infile;
	ofstream outfile, errorFile;
	double wage, hours, grossPay, ficaTax, incomeTax, netPay, taxWithheld;
	string Name;
	char Status;
	int exemptions, ID;

	infile.open(""); //Remember to write file name
	if (!infile)
	{
		cout << "Error file not found." << endl;
		system("pause");
		exit(1);
	}
	else
		cout << "Success!" << endl;

	outfile.open(""); //Remember to write file name			
	errorFile.open(""); //Remember to write file name

	while (infile)
	{
		infile >> Name >> wage >> hours >> exemptions >> Status;
		retrieveData(Name, wage, hours, exemptions, Status); // Here are the errors
		dataCalculations( wage,  hours,  exemptions, Status,  grossPay,  ficaTax, incomeTax,  netPay,  taxWithheld); //Here are the errors
		sendData(Name, ID,  hours,  wage, ficaTax, incomeTax, grossPay, netPay); //Here are the errors

	}

	infile.close();
	outfile.close();
	errorFile.close();

	system("pause");

	return 0;

}

//Check for valid data
void retrieveData(string N, double w, double h, int e, char S)
{
	if (w < 0 || h < 0 || S != 'M' || S != 'm' || S != 'S' || S != 's')
	{
		errorFile << "This employees data contains errors." << endl;
		errorFile << "Name: " << N << "\tHourly Wage: " << w << "\tHours Worked: " << h << "\tExemptions: " << e << "\tMarital Status: " << S;
		cout << "Error with employee data: " << N << endl;
	}
}

//Calculate data
void dataCalculations(double w, double h, int e, char S, double gP, double fT, double iT, double nP, double tW)
{
	bool overtime;
	double remainder;

	if (h < 40)
		overtime = true;
	else
		overtime = false;

	if (overtime = true)
	{
		remainder = h - 40;
		gP = (w * 40) + (remainder*1.5*w);
	}
	else if (overtime = false)
	{
		gP = w*h;
	}

	fT = gP*0.0565;
	iT = 73.08*e;

	if (S == 'M' || S == 'm')
	{
		if (iT >= 0 && iT <= 1515)
			tW = 0;
		else if (iT >= 1515 && iT <= 7624)
			tW = 187.15 + (iT*0.15 / 1515);
		else if (iT >= 7624)
			tW = 2020.42 + (iT*0.30 / 7624);
	}
	else if (S == 'S' || S == 's')
	{
		if (iT >= 0 && iT <= 721)
			tW = 0;
		else if (iT >= 721 && iT <= 7510)
			tW = 93.60 + (iT*0.28 / 721);
		else if (iT >= 7510)
			tW = 2767.16 + (iT*0.35 / 7510);
	}

	nP = gP - fT - iT - tW;
}

//Send data to file
void sendData(string N, int I, double h, double w, double fT, double iT, double gP, double nP)
{
	outfile << "Employee Name:" << N << endl;
	outfile << "Hours Worked:" << h << endl;
	outfile << "Hourly Wage:" << w << endl;
	outfile << "Fica Tax Deduction:" << fT << endl;
	outfile << "Income Tax Deduction:" << iT << endl;
	outfile << "Gross Pay:" << gP << endl;
	outfile << "Net Pay:" << nP << endl;
	outfile << endl;
}




See where you declare those functions and where you define them? They are different.

I have put where you declare the functions at the top of the program to where you define them at the bottom of the program right on top of each other below. I also took out the variable names. See the difference?

1
2
3
4
5
6
7
8
void retrieveData(string&, double&, double&, int&, char&);
void retrieveData(string,    double,   double,   int,    char)

void dataCalculations(double, double, int, char, double&, double&, double&, double&, double&);
void dataCalculations(double, double, int, char, double,    double,   double,   double,    double)

void sendData(string, int&, double, double, double, double, double, double);
void sendData(string, int,   double, double, double, double, double, double)


See the difference? In the definitions of those functions, you have some arguments that are not references (using the &) like you did when you declared them. This means you actually have TWO functions for all three of those functions. One of them has a definition, and the other function does not have a definition.

So when you try to call the functions, the compiler is telling you it doesn't know which one you want... the function with the reference or the one without it. Make all your arguments match up with both having &s or neither having &s, and you should be good to go.
Last edited on
Oh man thanks bro that completely worked, thanks for the help!
Topic archived. No new replies allowed.