### Assignment Help

Hey all, completely new to all of this and really needed some help on my one assignment.

Assignment: Write a program that asks for a loan amount, the number of years, and the annual interest rate. Use a function, CalcPayment to calculate the payment to amortize the loan, then return the value to main.

#include <iostream>
#include <cmath>
#include <iostream>

using namespace std;

int CalcPayment (double loan, interestRate, time, payment, years, interest)
{
time = years * 12
interestRate = interest * .01
CalcPayment = (loan (interestRate (1 + interestRate) pow (time))) / ((1 + interestRate) pow (time) - 1)

return CalcPayment;
}

int main ()
{
cout << "Enter the loan amount: " << endl;
cin >> loan;
cout << "Enter the number of years: " << endl;
cin >> years;
cout << "Enter the annual interest rate: " << endl;
cin >> interest;
cout << "Payment is ";
cout << CalcPayment << endl;
}
what is rhe problem?
I haven't compiled it yet...
why are you posting it then?
I continue to get a bunch of undeclared variables, such as, interestRate, loan, years, interest. how can i fix it?
declare them
`cout << CalcPayment << endl;`

That is not how to call the function.

Learn first, then code.

http://www.cplusplus.com/doc/tutorial/ and in particular http://www.cplusplus.com/doc/tutorial/functions/
#include <iostream>
#include <cmath>
#include <iostream>

using namespace std;

double CalcPayment (double loan, interestRate, time, payment, years, interest)
{
time = years * 12;
interestRate = interest * .01;
CalcPayment = (loan (interestRate (1 + interestRate) pow (time))) / ((1 + interestRate) pow (time) - 1)

return CalcPayment;
}

int main ()
{
double a, b, c, d;
a = CalcPayment;
b = loan;
c = years;
d = interest;
cout << "Enter the loan amount: " << endl;
cin >> b;
cout << "Enter the number of years: " << endl;
cin >> c;
cout << "Enter the annual interest rate: " << endl;
cin >> d;
cout << "Payment is " << a << endl;
}

I don't understand, so many "not declared". I'm very very very new to this...

When the execution gets to here:
`a = CalcPayment;`
it has never heard of any variable called CalcPayment.
so what do i have to do?
you are got a lot of readings to do buddy! you are still stuck on how to declare variables properly
CalcPayment is a function not a variable
do you want the total payment amount due at the end... do you want each month? each year?
I want the total payment due at the end.
here you go...

 ``12345678910111213141516171819202122232425262728293031323334353637`` ``````#include using namespace std; main(){ // declare your variables to allocate memory space double loanAmount, annualInterest; // declare double's to accept decimal numbers int years; // declare an int to accept a whole integer // ask the user to input the loan amount cout << "Loan amount: "; cin >> loanAmount; // ask the user to input the number of years cout << "Number of years: "; cin >> years; // ask the user to input the number of years cout << "Annual Interest Rate: "; cin >> annualInterest; // Calculate all of it and print it to screen cout << endl; cout << "Your total payment is: " << loanAmount + (loanAmount * (annualInterest/100)) * years << endl; cout << "Good Bye..." << endl; system("pause"); }``````
Topic archived. No new replies allowed.