I am attempting to write this code for class. However, when I submit the code, I keep getting back a 0%. I don't understand why. It runs, however, I still get a 0%. Any ideas?
"Write a program that accepts as input netBalance, d1, payment, d2, and interest rate per month (interestRate).
The program outputs the interest.
Format your output to two decimal places."
Those are the instructions. I feel as if I am getting a 0% due to not setting them to two decimal places? However, I am trying to use the setPrecision method but I am just lost.
A couple of things,
On line 33 and line 34, you are giving the average daily balance and interest. However, you are computing those after you tell the user.
Also, have you tried to compute some examples to see if it matches with the computation on Line 37? It could give you an idea if the computations on the program matches your own that you do on paper or calculator.
For setprecision, you need the #include <iomanip>
Take a look at the setprecision portion in this forum.
The formulas were given with the homework, (averageDailyBalance = (netBalance * d1 – payment * d2) / d1). So, I am just attempting to use it, along with (interest = averageDailyBalance * interest) that was given.
On line 37, based on the formula, i recommend changing from averageDailyBalance = (netBalance * d1 - payment * d2 / d1);
to averageDailyBalance = (((netBalance * d1) - (payment * d2)) / d1);
this is due to the order of math operations.
Thank-you so much for your help. I completed the assignment. It turns out the problem was with the formula, although it was provided with the homework - so I didn't question it! Just goes to show, I should double-check everything regardless!