Hello kadengolda,
It would help if you post the Specs, (specifications), i.e., instructions that you were given for this assignment. I have a feeling that you are missing something.
You have
balance = balance - interest;
. It seems to me that you should be adding "interest" here before you subtract the payment. Unless you were given the formula(s) to use I believe you are going about it wrong.
I'm trying to create a loop that calculates interest, subtracts it from the balance, and continues until the balance is equal to 0. |
At month 272 I found that "balance" is "0.0097878824153285002" and "interest" is " 0.00039151529661314002" and "minPayment" is "0.040000000000000001" not that you use "minPayment" in the "calcfuturebalance" function or anywhere else.
By what you are doing: "0.00978" minus "0.00039" is "0.00939" and that is at month 272 or 22 years.
The real question here is if this program is for credit card debt or for a conventional bank loan. This will most likely make a difference in how interest is calculated.
To understand how credit card interest is figured I found this site
https://www.nerdwallet.com/blog/credit-cards/how-credit-card-interest-calculated/ to be useful.
I admit I am now well versed in the math for this, but my simple understand is that (interest = balance * interestRate) then interest is added to balance before you subtract the payment.
Then there is "minPayment". I am not sure if you intend this to be a percentage of the balance or a dollar amount.
Since you included "iomanip" put this before the while loop in "main".
std::cout << std::fixed << std::showpoint << std::setprecision(2);
Then for the "cout" in the while loop try this:
cout << std::setw(3) << month << " " << std::setw(7) << balance << " " << std::setw(5) << interest << endl;
. These two lines will line up the output better.
I also noticed you included the header file "cmath". Simple "* / + -" does not require this header file.
Hope that helps,
Andy