I have two function in the same class. In the first function I return a value, and I need to use this value in another function. I am returning by value.

double Loan::monthlyPayment(double anAmount, double anInterestRate, int term){
    double payment = ((anAmount * anInterestRate ) * ((anInterestRate +1)/((anInterestRate +1)*exp(term)-1)));

    return payment;

I need to access the returned payment in this function:

The Loan class should have a makePayment(double amount) method that 
allows payments to the loan to be made. A payment is assumed to 
happen once a month. When a payment is made the balance is first 
increased by 1/12 of the interest rate and then the amount is 
subtracted from the balance. Modify the main program given to 
demonstrate that this method works properly.
double Loan::makePayment(double amount){
          // Get the amount to pay
     amount = monthlyPayment(???)+(1/12)(term);
     return amount;

Also, how do I access the returned value from this makePayment(amount) function in another class?

Thank you!

4 Years
Discussion Span
Last Post by sarah.mathieson.7

Yes. If intrest and the term are class members then you can pass them to or use them directly in the monthly payment function.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.