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?

Ancient Dragon commented: Thanks for using code tags correctly +20

It would help if you get a clean compile. There are several syntax errors in the code you posted. Impossible to help you until they are corrected.

If your debt grows quicker than the min repayment can reduce it, then it will grow and grow until it reaches infinity (which is what #INF means).

If your debt grows quicker than the min repayment can reduce it, then it will grow and grow until it reaches infinity (which is what #INF means).

Yes, just like people's credit cards :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.