Hey, I'm making a very simple program to find out how many months it would take to pay off credit card debt
// Calculate Credit Card Debt and How long it would take to pay it off
#include <iostream.h>
using namespace std;
int main(void) {
double Debt, APR, MinMonthPay;
unsigned int MonthsToPay = 0;
cout << " CREDIT CARD DEBT CALCULATOR\n\n";
cout << " HOW MUCH DEBT HAVE YOU USED?: ";
cin >> Debt;
orgDebt = Debt;
cout << " WHAT IS YOUR APR RATE?: ";
cin >> APR;
APR /= 1200;
APR++;
cout << " WHAT IS THE MINIMUM MONTHLY PAYMENT?: ";
cin >> MinMonthPay;
while(Debt > 0) {
Debt = (Debt - MinMonthPay) * APR;
MonthsToPay++;
cout << ' ' << Debt << endl;
}
cout << " IT WOULD TAKE " << MonthsToPay
<< " MONTHS TO PAY OFF THE DEBT!\n";
cout << ' ';
system("PAUSE");
return 0;
}
Can anyone tell me why this sometimes creates an endless loop because Debt = 1.#INF?
I made it output Debt each iteration and under some conditions it becomes 1.#INF and I don't know why! I know one example that will cause this is this input:
4500
19
24
however,
4500
19
80
works! can anyone help?