Hi guys, I'm supposed to make a program that calculates how many months it would take to pay off your credit card balance with a 14% yearly interest rate. I've written out what I believe to be it but I end up getting this.
http://omg.wthax.org/error_2.png
The program doesn't seem to continue after typing in the balance, or rather seems to be stuck in an infinite loop. Can anyone explain why this is happening?
Edit- After looking more closely, it seems the problem is that the second while loop never ends since it's never greater than 12. Would that be the problem?
Edit2- It seems I fixed it with a simple AND statement.
Edit3- On trying the program out, it seems to have the same problem when you type in a value higher than 1900...
http://omg.wthax.org/error_3.png
# include <iostream>
using namespace std;
int main()
{
int payment = 20;
int month = 0;
float balance;
float interest;
int counter = 0;
//Ask what their balance is.
cout << "How much money did you waste?" << endl;
cin >> balance;
//Calculate the time needed to pay off the balance.
while (balance > 0)
{
while (counter < 12 && balance > 0)
{
++ month;
++ counter;
balance = balance - payment;
if (counter == 12)
{
counter = 0;
interest = balance * .14;
balance = balance + interest;
}
else
{
balance = balance;
}
}
}
cout << "It would take you " << month << " months to pay off your "
<< "balance." << endl;
}