I'm doing an assignment for school. The program is used to calculate how many months it would take to pay off a loan. The stuff after the loop is just temporary. This is my first time trying to work with loops and I really don't know what I'm doing haha. After the user input, the program hangs at the loop.
It looks here as if your using the while loop in the wrong context. The while loop is basically used to continuously repeat a sequence of events if the condition is true. I believe what you need here is the if function.
e.g:
1 2 3 4 5 6 7 8 9 10
if (age > 21){
cout << "You're legal to drink. Please do so responsibly." << endl;
}
else {
cout << "Your not old enough to drink!" << endl;
}
OK, there was a problem with the monthly payments. I fixed that so now I think that part of the program works. But I also have to make it output a warning if the monthly payment is too low. Not sure how to implement this. This is what I've got, if the payment is too low then the program hangs as before.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
if (monthlyPayment > intPerMonth)
{
while (loan > 0)
{
intPerMonth = monthlyPayment - loan * monthlyInt;
loan = loan - intPerMonth;
months ++;
}
cout << "It will take you " << months << " months to pay off your loan." << endl;
}
else
cout << "You're not paying enough." << endl;
cout << intPerMonth << endl;
cout << loan << endl;
system("PAUSE");
return 0;
}