Undefined Reference to "function" error

Hello! I am new to this forum and to coding so any pointers would be greatly appreciated. I am currently working on a code, but I keep getting a error as follows:

[Linker error] undefined reference to 'getHoursOfTheWeek(double)'
[Linker error] undefined reference to 'getGrossPay(double)'
[Linker error] undefined reference to 'getStateTax(double)'
[Linker error] undefined reference to 'getFederalTax(double)'
[Linker error] undefined reference to 'getFICA(double)'
[Linker error] undefined reference to 'getWithHoldingAmount(double)'

I have been trying to debug this error for hours and I am completely stumped. Any help would be appreciated, and my apologies if I didn't post correctly.

Project 4 Code:

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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//

//BEGIN

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

using namespace std;

string getUserName();
double getPayRate();
double getTotalPay();
double getGrossPay(double GrossPay);
double getStateTax(double StateTax);
double getFederalTax(double FederalTax);
double getHoursOfTheWeek(double HoursOfTheWeek);
double getFICA(double FICA);
double getWithHoldingAmount(double WithHolding);
void displayAmountDue(string UserName,double GrossPay,double WithHolding,double NetPay);


int main()
{
    string UserName;
    double PayRate, TotalPay, GrossPay, StateTax, FederalTax, FICA, WithHolding;
    
    //Get users name
    UserName = getUserName();
    
    //Get hourly pay rate
    PayRate = getPayRate();
    
    //Get Hours of the week
    TotalPay = getHoursOfTheWeek(TotalPay);
    
    //Calculate gross pay
    GrossPay = getGrossPay(GrossPay);
    
    //Calculate state tax
    StateTax = getStateTax(StateTax);
    
    //Calculate federal tax
    FederalTax =  getFederalTax(FederalTax);
    
    //Calculate FICA tax
    FICA = getFICA(FICA);
    
    //Calculate WithHolding amount
    WithHolding = getWithHoldingAmount(WithHolding);
    
    //Display results
    displayAmountDue(UserName, GrossPay, WithHolding, NetPay);
    
    return 0;
}

string getUserName()
{
    string UserName;
    cout<<"Please enter your name: ";
    cin>>UserName;
    
    return UserName;
}

double getPayRate()
{
    double PayRate;
    cout<<"Please enter your hourly pay: ";
    cin>>PayRate;
    
    return PayRate;
}

double getHoursOfTheWeek(int workDay, int TotalHours)
{
       int m;
       cout<<"How many days have you worked this week?";
       cin>>workDay;
       
       if (workDay == 1)
       {
       cout<<"Please enter the amount of hours you have worked on Monday: ";
       cin>>m;
       
       TotalHours = m;
       cout<<"Your total hours are: "<<TotalHours<<endl;
       
      
      return TotalHours;
       }
       
       else if (workDay == 2)
        {
            int m, t;
            cout<<"Please enter the amount of hours you have worked on Monday: ";
            cin>>m;
            cout<<"Please enter the amount of hours you have worked on Tuesday: ";
            cin>>t;
            
            TotalHours = m+t;
            cout<<"Your total hours are: "<<TotalHours<<endl;
            
            return TotalHours;
        }
        else if (workDay ==3)
        {
            int m, t, w;
            cout<<"Please enter the amount of hours you have worked on Monday: ";
            cin>>m;
            cout<<"Please enter the amount of hours you have worked on Tuesday: ";
            cin>>t;
            cout<<"Please enter the amount of hours you have worked on Wednesday: ";
            cin>>w;
            
            TotalHours = m+t+w;
            cout<<"Your total hours are: "<<TotalHours<<endl;
            
            return TotalHours;
        }
        else if (workDay ==4)
        {
            int m, t, w, th;
            cout<<"Please enter the amount of hours you have worked on Monday: ";
            cin>>m;
            cout<<"Please enter the amount of hours you have worked on Tuesday: ";
            cin>>t;
            cout<<"Please enter the amount of hours you have worked on Wednesday: ";
            cin>>w;
            cout<<"Please enter the amount of hours you have worked on Thursday: ";
            cin>>th;
            
            TotalHours = m+t+w+th;
            cout<<"Your total hours are: "<<TotalHours<<endl;
            
            return TotalHours;
        }
        else if (workDay ==5)
        {
            int m, t, w, th, f;
            cout<<"Please enter the amount of hours you have worked on Monday: ";
            cin>>m;
            cout<<"Please enter the amount of hours you have worked on Tuesday: ";
            cin>>t;
            cout<<"Please enter the amount of hours you have worked on Wednesday: ";
            cin>>w;
            cout<<"Please enter the amount of hours you have worked on Thursday: ";
            cin>>th;
            cout<<"Please enter the amount of hours you have worked on Friday: ";
            cin>>f;
            
            TotalHours = m+t+w+th,f;
            
            cout<<"Your total hours are: "<<TotalHours<<endl;
            
            return TotalHours;
        }
}

double GetGrossPay(double TotalHours, double PayRate)
{
      double GrossPay;
      GrossPay = TotalHours * PayRate;
      
      return GrossPay;
}

double GetStateTax(double GrossPay)
{
    double StateTax;
    StateTax = GrossPay * 1.25;
       
    return StateTax;
}

double GetFederalTax(double GrossPay)
{
       double amount, FederalTax;
       
       if (GrossPay<500)
       {
            amount = GrossPay * .15;
       }
       
       else
       {
           amount = GrossPay * .25;
       }
       
       return FederalTax;
}

double GetFica(double GrossPay)
{
       double FICA;
       
       FICA = GrossPay * 7.65;
       
       return FICA;
}

double getWithHoldingAmount(double WithHolding, double StateTax, double FederalTax, double FICA)
{
       WithHolding = StateTax + FederalTax + FICA;
       
       return WithHolding; 
}
void displayAmountDue(string UserName, double GrossPay, double WithHolding))
{
     cout<< "UserName:                 "<<UserName<<endl;
     cout<< "Gross Pay:                "<<GrossPay<<endl;
     cout<< "Total Withholding amount: "<<WithHolding<<endl;
}

//END

Lines 11-20 are the function prototypes. They need to match the actual functions written at the bottom of this listing. When I say match, I mean that the return type, the name of the function, and the types of all the parameters should match.

This code compiles, because you made a promise (those prototypes) that those functions would be defined. However, when the linker got a hold of your code, it couldn't find those definitions! It only found definitions for other functions that had the same name, but all the parameter types were different.
Ahh, that makes sense. No wonder it couldn't link the functions. I guess I've been staring at this for too long and overlooked a simple mistake. With a little debugging and slight changes it finally compiles! Thank you very much for your time, I greatly appreciate it.

-Patrick
Topic archived. No new replies allowed.