1

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?

Votes + Comments
Thanks for using code tags correctly
3
Contributors
3
Replies
5
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

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.

0

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).

0

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 :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.