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!

Well the intrest rate and term should be members of the class so you can use them in mutiple functions.

even if the function prototype for makePayment is makePayment(double amount)?

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.