Oct 23, 2012 at 8:57pm UTC
Hello, this is a program that was assigned for homework and i figured most of it out but cant figure out why program wont stop, its like stuck in an infinate loop(?). But it compiles so if anyone wants to plug it in and check it works.
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
//defined variables
int loanAmount;
double interestRate;
double interestRatePerMonth;
double monthlyPayment;
double paymentPrincipal;
double months;
cout << fixed << showpoint;
cout << setprecision (2);
cout << "Enter your loan amount: ";
cin >> loanAmount;
cout << endl;
cout << "Enter your interest rate:";
cin >> interestRate;
cout << endl;
interestRatePerMonth = (1 + interestRate) / 12 - 1;
cout << "Enter your monthly payment: ";
cin >> monthlyPayment;
cout << endl;
months = 0;
while (months < 12)
{
if (monthlyPayment < 0)
{
cout << "Your monthly payment is too low." << endl;
cin >> monthlyPayment;
continue;
}
paymentPrincipal = monthlyPayment - (loanAmount*
interestRatePerMonth);
loanAmount = loanAmount - paymentPrincipal;
cout << "Loan Amount: "
<< loanAmount
<< endl;
cout << "Payment Principal: "
<< paymentPrincipal
<< endl;
}
system("pause");
return 0;
}
Oct 23, 2012 at 9:03pm UTC
What you do is what you get.
I have question to you why did you decide that the loop can not be infinite?