Loan Issue

Super frustrated. I'm trying to determine how to do this incremental loan calculator.

These are the requirements.

Input should be:
-Loan.
-Amount of years (you want displayed in months).
-InterestRate per month.
Output should be:
-Loan amount (decreasing) per month.
- Monthly Payment.
- Monthly Interest.


This is my progress. I'm running into a compiler error with the pow function on line 32. And when I did get the results before, the output format was wrong. Desperate need of help!

-Solved
Last edited on
Hi,

On line 31, the compiler does integer division before implicitly casting to double. Do this instead:

monthlyRate /= 100.0 / 12.0;

This forces the double type throughout. I always put numbers before and after the decimal point for doubles.

Why do you use the float type? The precision of float is easily exceeded, so that is why double is the default.


In function 'int main()': 
32:74: error: expected ')' before 'pow' 
32:88: error: expected ')' before ';' token


If you put white space around your operators and parentheses, these errors might be more apparent :

monthlyPayment = ( principalAmount * monthlyRate) / ( 1.0 - ( 1.0 / ( 1.0 + monthlyRate ) pow( nMonths ) ) );

pow takes 2 arguments, and you are missing an operator before it, and missing a parentheses. If your editor doesn't match parentheses automatically and anything thing else that come in pairs, then it's a good idea to type both the opening and closing ones straight away, then go back and fill in what's inside. That way you will never have mismatched pairs.

On line 34, is interestAdd uninitialised? A golden rule is to make sure all variables are initialised.

God Luck !!




Last edited on
Topic archived. No new replies allowed.