(taken from the assignment page)

"Your program will ask the user to enter the amount of money they want to borrow, the interest rate, and the monthly payment amount. Your program will then determine how many months it will take to pay off that loan, what the final payment amount will be, and how much interest was paid over that time. If the monthly payment amount isn't high enough to pay off more than one month's interest, your program should notify the user what the minimum monthly payment is. "

i'm getting errors that all three variables in the getInput(principal, interestRate, monthlyPayment); function line are all being used before their values are set.

i'm also getting errors that say payLoan(principal, monthlyInterest, monthlyPayment, months, total_Interest); function monthlyInterest and total_Interest are being used before their values are set also.

my last error says that for the line monthlyInterest = interestRate / month; interestRate is being using before its value is set.

i know these errors are easy fixes but i've been trying for a couple hours to fix them and i'm really frustrated. i feel dumb for not being able to figure it out myself! argh. if anyone could give me a hand that would be great. =]

here is my code:

Code:#include <iostream> #include <iomanip> using namespace std; const int month = 12; // global constant for amount of months void getInput(double, double, double); double payLoan(double, double, double, int, double); int main() { double principal, // amount user wants to borrow interestRate, // annual interest rate (as a percent) monthlyPayment, // amount user has to pay per month monthlyInterest, // amount of interest user has to pay per month total_Interest; // total amount of interest user has to pay int months = 1; // total amount of months loan will be repaid in cout << "** Welcome to the Consumer Loan Calculator **"; getInput(principal, interestRate, monthlyPayment); payLoan(principal, monthlyInterest, monthlyPayment, months, total_Interest); cout << "** Don't get overwhelmed with debt! **"; return 0; } //************************************************************************** // This functions asks the user how much they want to borrow, the annual * // interest rate (expressed as a percent) and how much the user has to pay * // monthly. * //************************************************************************** void getInput(double principal, double interestRate, double monthlyPayment) { do { cout << "How much do you want to borrow?"; cin >> principal; } while (principal <= 0); cout << "You must enter a positive number! \n"; do { cout << "What is the annual interest rate expressed as a percent?"; cin >> interestRate; } while (interestRate <= 0); do { cout << "What is the monthly payment amount?"; cin >> monthlyPayment; } while (monthlyPayment <= 0); cout << "You must enter a positive number! \n"; } //*************************************************************************** // This function calculates how many months it will take for the loan to be * // paid off, how much the final payment will be and the total amount of * // interest to be paid over the course of the repayment period. * //*************************************************************************** double payLoan(double principal, double monthlyInterest, double monthlyPayment, int months, double total_Interest) { double interest, payment, interestRate, finalPayment, leastPayment; cout << fixed << showpoint << setprecision(2); monthlyInterest = interestRate / month; //int months = 1; while (months++) { while (principal > monthlyPayment) { interest = principal * monthlyInterest; payment = monthlyPayment - interest; if (payment < 1) { leastPayment = interest + 1; cout << "You must make payments of at least $" << leastPayment << endl; cout << "Because your monthly interest is $" << interest << endl; } principal = principal - payment; total_Interest += interest; } if (principal < monthlyPayment) break; } finalPayment = principal + principal * interest; total_Interest += interest; cout << "Your debt will be paid off after" << months << "months, "; cout << "with a final payment of just $" << finalPayment << endl; cout << "The total amount of interest you will pay during that time is $" << total_Interest << endl; return 0; }