-
Probably a simple error
I'm new with C++ so no flame. I'm getting this error
[Linker error] undefined reference to `DetermineCost(double, double)'
ld returned 1 exit status
Here is my code
Code:
#include <iostream>
#include <iomanip>
using namespace std;
void ExplainProgram();
double GetIncome();
double DetermineCost(double income, double rate);
void DisplayResults(double income, double tax);
const int MAX1 = 5000; // max income for the first category
const int MAX2 = 10000; // max income for the second category
const int MAX3 = 20000; // max income for the third category
const int MAX4 = 40000; // max income for the fourth category
const double RATE1 = .03;
const double RATE2 = .055;
const double RATE3 = .108;
const double RATE4 = .237;
int main()
{
double income; // total income of the person
double rate; // tax rate based on persons income
double tax; // tax owned rounded to the nearest dollar
ExplainProgram();
income = GetIncome();
tax = DetermineCost(income, rate);
DisplayResults(income, tax);
system("PAUSE");
return 0;
}
// Function: ExplainProgram
// Task: Explain the purpose of the program to the user
// Preconditions: none
// Postconditions: the explaination appears on the screen
void ExplainProgram()
{
cout << "Given the income of a person, this program will find and print\n"
<< "the cost of taxes\n\n";
}
// Function: GetIncome
// Task: Get the income of the person from the user
// Preconditions: none
// Postconditions: the income of the person (double) will be returned
double GetIncome()
{
double totalIncome;
cout << "Enter the persons income: ";
cin >> totalIncome;
if (totalIncome < 0)
{
cerr << "ERROR: persons income cannot be negative!!!\n";
system("PAUSE");
exit(1);
}
return totalIncome;
}
// Function: DetermineCost
// Task: Given the person's income determine the total tax cost
// Preconditions: the income of the person is provided as a double passed by value
// Postconditions: the tax amount in dollars (double) is returned
double DetermineCost(double incomeOfPerson, double tax, double income)
{
if (incomeOfPerson <= MAX1)
{
tax = income;
return tax;
}
else if (incomeOfPerson <= MAX2)
{
tax = income * RATE1;
return tax;
}
else if (incomeOfPerson <= MAX3)
{
tax = income * RATE2;
return tax;
}
else if (incomeOfPerson <= MAX4)
{
tax = income * RATE3;
return tax;
}
else
{
tax = income * RATE4;
return tax;
}
}
// Function: DisplayResults
// Task: display the tax owned to the nearest dollar for the user to see
// Preconditions: the income of the person (double) and the tax rate (double)
// are passed by value
// Postconditions: the income and rate are displayed to the screen
void DisplayResults(double income, double tax)
{
cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(2);
cout << "An income of $" << income << " will own $" << tax
<< " for taxes.\n";
}
Help with this will be greatly appreciated.
-
Code:
double DetermineCost(double income, double rate);
// ...
tax = DetermineCost(income, rate);
//...
double DetermineCost(double incomeOfPerson, double tax, double income)
{
if (incomeOfPerson <= MAX1)
{
//...
As you can see, you define some function "DetermineCost" that takes two arguments, but your never implementing that function. Your implementing a function with the same name that takes three arguments. You need to change your code so that these three occurrences all have the same number of arguments (i.e. all have 2 doubles, or all have 3 doubles).
Of course you can have multiple functions with the same name ("function overloading"), but you need to implement each one if thats the case. If this is the case, then you need to also implement "DeterminCost(double, double)". I doubt you actually want to overload the function though.