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;
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?
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.
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.
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()
{
...
}