I need some help with C++ classes. I can not get my Monthly payments and my Total pay back to print using a class for calculating a mortgage payment. I am not sure what I am doing wrong.
I have tried a couple of things, but still can not seem to make it work. Below are the most recent errors I am getting.
Any fixes to my code to get me back on track are appreciated.
/The type of errors
//C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6EX13_06.cpp(104) : error C2248: 'pay' : cannot access private member declared in class 'Payment'
// C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(19) : see declaration of 'pay'
//C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(106) : error C2248: 'pay' : cannot access private member declared in class 'Payment'
// C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(19) : see declaration of 'pay'
//C:\Program Files\Microsoft Visual Studio\MyProjects\tan\Ex13_6\EX13_06.cpp(106) : error C2297: '*' : illegal, right operand has type 'float (__thiscall Payment::*)(void)'
//Error executing cl.exe.
//EX13_06.obj - 3 error(s), 0 warning(s)
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
class Payment
{
private:
float loan;
float rate;
float years;
float payment;
float term;
float pay;
float tm;
public:
float getLoan(void);
float getRate(void);
float getYears(void);
void setData(float, float, float);
float calcTerm(void);
float calcPayment();
};
// SetData copies the argument to private members
// loan, rate, years
void Payment::setData(float l, float r, float y)
{
loan = l;
rate = r;
years = y;
}
// getLoan returns the value in the private member loan amt.
float Payment::getLoan(void)
{
return loan;
}
// getRate returns the value in the private member rate amt.
float Payment::getRate(void)
{
return rate;
}
// getYears returns the value in the private member years.
float Payment::getYears(void)
{
return years;
}
float Payment::calcPayment()
{
payment = (loan * rate / 12.0 * term) / (term - 1.0);
return pay;
}
float Payment::calcTerm()
{
term = pow((1 + rate / 12.0), 12.0 * years);
return tm;
}
void main(void)
{
Payment mortgage;
float mtg_loan;
float mtg_rate;
float mtg_years;
cout << "Loan amount: $";
cin >> mtg_loan;
cout << "Annual Interest Rate (Enter .12 for 12%): ";
cin >> mtg_rate;
cout << "Years of loan: ";
cin >> mtg_years;
mortgage.setData(mtg_loan, mtg_rate, mtg_years);
//mortgage.setDataoth(mtg_payment);
//cout <<mortgage.getLoan() <<endl;
cout << "Here is your data:\n" << endl << endl;
cout <<"Loan amount: $" <<mortgage.getLoan() <<endl;
cout <<"Annual Interest Rate: " << mortgage.getRate() <<endl;
cout <<"Years of loan: " <<mortgage.getYears() << endl;
//cin >> mortgage.getYears() <<endl;
//what I want to do
//cout << "Monthly payment: $" << payment << endl;
cout << "Monthly payment: $" << mortgage.pay << endl;
//what I want to do
////cout << "Total Pay Back: $" << (payment*years*12) << endl;
cout <<"Total Pay Back: $" << (mortgage.pay*mortgage.getYears*12) <<endl;
}