error

I created different style of program this time, but they give me error::/tmp/cczAJxFX.o: In function `main':
:(.text.startup+0x41): undefined reference to `Loan::getMonthlyPayment(double, int, double)'
:(.text.startup+0x5e): undefined reference to `Loan::getTotalPayment(double, int, double)'
collect2: error: ld returned 1 exit status
can someone teach me how to fix it directly?? Thank you

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
#include <iostream>
#include <cmath>
using namespace std;

class Loan
{
public:
  Loan();
  Loan(double newAnnualInterestRate, int newNumberOfYears, double newLoanAmount);
  double getAnnualInterestRate() const;
  int getNumberOfYears() const;
  double getLoanAmount() const;
  void setAnnualInterestRate(double newAnnualInterestRate);
  void setNumberOfYears(int newNumberOfYears);
  void setLoanAmount(double newLoanAmount);
  double getMonthlyPayment() const;
  double getTotalPayment() const;
  static double getMonthlyPayment(double annualInterestRate, int numberOfYears, double loanAmount);
  static double getTotalPayment(double annualInterestRate, int numberOfYears, double loanAmount);

private:
  double annualInterestRate;
  int numberOfYears;
  double loanAmount;
};

Loan::Loan()
{
  annualInterestRate = 5.5;
  numberOfYears = 15;
  loanAmount = 40000;
}

Loan::Loan(double newAnnualInterestRate, int newNumberOfYears, double newLoanAmount) 
{
  annualInterestRate = newAnnualInterestRate;
  numberOfYears = newNumberOfYears;
  loanAmount = newLoanAmount;
}

double Loan::getAnnualInterestRate() const
{
  return annualInterestRate;
}

int Loan::getNumberOfYears() const
{
  return numberOfYears;
}

double Loan::getLoanAmount() const
{
  return loanAmount;
}

void Loan::setAnnualInterestRate(double newAnnualInterestRate)
{
  annualInterestRate = newAnnualInterestRate;
}

void Loan::setNumberOfYears(int newNumberOfYears)
{
  numberOfYears = newNumberOfYears;
}

void Loan::setLoanAmount(double newLoanAmount)
{
  loanAmount = newLoanAmount;
}

double Loan::getMonthlyPayment() const
{
  double monthlyInterestRate = annualInterestRate / 1200;
    return loanAmount * monthlyInterestRate / (1 - (pow(1 / (1 + monthlyInterestRate), numberOfYears * 12)));
}
double Loan::getTotalPayment() const
{
    double monthlyInterestRate=annualInterestRate/1200;
    return (loanAmount * monthlyInterestRate / (1 - (pow(1 / (1 + monthlyInterestRate), numberOfYears * 12)))*180);
}
int main(){
Loan newLoan;
newLoan.getMonthlyPayment(5.5, 15, 40000);
newLoan.getTotalPayment(5.5, 15, 40000);
cout<<" your monthly payment is "<<newLoan.getMonthlyPayment()<<".";
cout<< "Your total payment is"<< newLoan.getTotalPayment()<<endl;
}
Last edited on
A linker error.

Your program does not contain implementation for the member functions that you do declare on lines 18-19.
hello can you give me some clue or example how to fix link error ?? Thank You!!
Last edited on
Write the missing functions that the error mentions.
but i already included the formula inside my class declaretion , should i wrtie another one?? Thank you
Do the type and number of parameters match? I don't see where you implemented a member function with the following signature: Loan::getTotalPayment(double, int, double) I only see the double Loan::getTotalPayment() const function.

but i already included the formula inside my class declaretion

On what lines of your code is that formula?
Topic archived. No new replies allowed.