C++ undefined reference and exit error...plz help?

I'm using Dev C++ compiler. I keep getting these two errors. [Linker error] undefined reference to `taxAmount(int, double, double, int)' and ld returned 1 exit status. This is my code. plz help.

#include <iostream>
#include <string>

using namespace std;

int getChildren ();

double taxAmount(int, double, double, int);

void getData ();

int main ()

{
getData();
system("PAUSE");
return 0;
}

void getData ()

{
char status, answer;
int numChildren;
double salary, pensionAmount, deductAmount;
int numPeople, standardExemption;
double tax;

cout<<"Enter 'm'arried or 's'ingle:";
cin>>status;
cout<<endl;

if (status=='m'||status=='M')
{
numChildren=getChildren();
standardExemption=7000;

cout<<"Do both spouses earn an income? Enter 'Y'es or 'N'o: ";
cin>>answer;
cout<<endl;

if (answer=='y'||answer=='Y')
{
cout<<"Please enter combined salary: ";
cin>>salary;
cout<<endl;
}
else if (answer=='n'||answer=='N')
{
cout<<"Please enter your salary: ";
cin>>salary;
cout<<endl;
}
numPeople=2+numChildren;
}
else
{
cout<<"Please enter your salary: ";
cin>>salary;
cout<<endl;
standardExemption=4000;
numPeople=1;
}

cout<<"Please enter pension plan amount: ";
cin>>pensionAmount;
cout<<endl;


tax = taxAmount(numPeople, salary, pensionAmount, standardExemption);

cout<<"Your tax amount is: "<<tax<<endl;

}
int getChildren ()

{
int children;

cout<<"Enter number of children under 14: ";
cin>>children;
cout<<endl;

return children;


}

Where have you defined taxAmount?
I've reworked it and this is what I get. It now compiles and asks me for all the right information. However, it doesn't compute the tax. Any ideas what's wrong now?



#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int getChildren ();

double taxAmount(int, double, double, int);

void getData ();

int main ()

{
getData();
int getChildren ();
double taxAmount(int, double, double, int);
system("PAUSE");
return 0;
}

void getData ()

{
char status, answer;
int numChildren;
double salary, pensionAmount, deductAmount;
int numPeople, standardExemption;
double tax;

cout<<"Enter 'm'arried or 's'ingle:";
cin>>status;
cout<<endl;

if (status=='m'||status=='M')
{
numChildren=getChildren();
standardExemption=7000;

cout<<"Do both spouses earn an income? Enter 'Y'es or 'N'o: ";
cin>>answer;
cout<<endl;

if (answer=='y'||answer=='Y')
{
cout<<"Please enter combined salary: ";
cin>>salary;
cout<<endl;
}
else if (answer=='n'||answer=='N')
{
cout<<"Please enter your salary: ";
cin>>salary;
cout<<endl;
}
numPeople=2+numChildren;
}
else
{
cout<<"Please enter your salary: ";
cin>>salary;
cout<<endl;
standardExemption=4000;
numPeople=1;
}

cout<<"Please enter pension plan amount: ";
cin>>pensionAmount;
cout<<endl;
}

int getChildren ()

{
int children;

cout<<"Enter number of children under 14: ";
cin>>children;
cout<<endl;

return children;

}
double taxAmount(int, double, double, int)
{
int numPeople;
double tax;
double salary, pensionAmount;
int standardExemption;

if (salary <=15000.00)
{
"taxAmount=(salary-((numPeople*1500.00)+pensionAmount+standardExemption))*15%";
}
else if (salary>15000.00||salary<=40000.00)
{
"taxAmount=2250.00+((((numPeople*1500.00)+pensionAmount+standardExemption))-15000.00)*25%";
}
else (salary>40000.00);
{
"taxAmount=8460.00+((((numPeople*1500.00)+pensionAmount+standardExemption))-40000.00)*35%)";
}

tax = taxAmount(numPeople, salary, pensionAmount, standardExemption);


cout<<"Your tax amount is: "<<tax<<endl;


return 0;
}
Please use [code] [/code] tags around your source code. Makes it easier to read, and keeps the original indentation.
I don't even know what that is.
1
2
3
4
5
6
double taxAmount(int, double, double, int)
{
int numPeople;
double tax;
double salary, pensionAmount;
int standardExemption;


That's not how you "name" the parameters of a function. Maybe you want this:
1
2
double taxAmount(int numPeople, double tax, double salary, double pensionAmount, int standardExemption)
{

Ok I did that. Took out the declarations. Now it says there are too few arguments.
Yes. Because you need to change the original declaration too, from
double taxAmount(int, double, double, int);
to
double taxAmount(int, double, double, double, int);

See that extra double in there? And when you use that function in your program you'll need to add the extra parameter too.
The extra parameter is in the original declaration (I fixed it when I changed it the first time), but it's still saying too few arguments.
It seems to me you do not understand how functions work.
In main() you are calling double taxAmount(int, double, double, int);.
Those ints and doubles should be the names of variables.

The problem in your code is that your functions don't exchange information.

Please read this tutorial:
http://www.cplusplus.com/doc/tutorial/functions/

Edit: your easy way out of this would be to declare the variables you use in more than one function as global variables. Global variables are on the outside of functions, and not inside of them. Using globals, their value will be preserved if changed in a function, so your functions will be able to communicate somewhat.

1
2
3
4
5
6
7
8
#include <...>

int global; // this is a global variable

void main()
{
    ...
}


Last edited on
Also:
1
2
3
4
5
6
7
8
9
10
11
12
if (salary <=15000.00)
{
    "taxAmount=(salary-((numPeople*1500.00)+pensionAmount+standardExemption))*15%";
} 
else if (salary>15000.00||salary<=40000.00)
{
    "taxAmount=2250.00+((((numPeople*1500.00)+pensionAmount+standardExemption))-15000.00)*25%";
} 
else (salary>40000.00);
{
    "taxAmount=8460.00+((((numPeople*1500.00)+pensionAmount+standardExemption))-40000.00)*35%)";
} 

This code does not assign taxAmount anything, it's just a string. Once you've done the above remove the quotation marks
taxAmount is a function, not a variable... so maybe that's how OP tried to set its parameters.
Topic archived. No new replies allowed.