display 0 in my proggram??
Apr 10, 2016 at 5:39am UTC
my program display 0 after run after i enter the loan money, rates and year
thank you for your helps
please point out my errors, i am a beginning C++programer:
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
#include<iostream>
using namespace std;
#include <iomanip>
#include <cmath>
class loan{
private :
double rates;
double amount;
double payment;
double totalloan;
double percent;
int years;
public :
double annualInterestRate(double );
int NumberOfYears(int );
double loanAmount(double );
double monthlypayment;
double getannualInterestRate(double );
int getNumberOfYears(int );
double getloanAmount(double );
double setannualInterestRate(double );
double setNumberOfYears(int );
double setloanAmount(double );
double getMonthlyPayment(double );
double getTotalPayment(double );
};
double loan::setannualInterestRate(double rates){
return rates;
}
double loan::setNumberOfYears(int years){
return years;
}
double loan::setloanAmount(double amount){
return amount;
}
double loan::getannualInterestRate (double percent) {
return percent;
}
int loan::getNumberOfYears(int years){
return years;
}
double loan::getloanAmount(double money){
return money;
}
double loan::getMonthlyPayment(double payment){
return payment=((1 +percent)* amount)/years;
}
double loan::getTotalPayment(double totalloan){
return totalloan=payment*years;
}
int main()
{
int years;
double annualInterestRate;
double loanAmount;
double payment;
double totalloan;
cout<<" Enter the loan Amount" ;
cin>>loanAmount;
cout<<" Enter the annuak interest rate of the loan:" ;
cin>>annualInterestRate;
cout<<" Enter the number of years for the loan" ;
cin>>years;
cout<<" your monthly payment is " <<payment<<"." ;
cout<< "Your total payment is" << totalloan<<endl;
}
Last edited on Apr 10, 2016 at 5:40am UTC
Apr 10, 2016 at 5:44am UTC
You need to create an object for a class.
Read about classes.
When you create a class, you need to make an object in order to use the functions and variables.
Like this:
1 2
loan myLoan;
std::cin >> myLoan.payment;
EDIT:
I noticed that you made your payment and rates variables private, make them public to access them or make a public function that sets the variables.
Last edited on Apr 10, 2016 at 5:45am UTC
Topic archived. No new replies allowed.