_
Thanks for catching the ";"'s at end of the two while statements. I must have overlooked them.
Here is the updated code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
#include <iostream>
using namespace std;
int main()
{
double monthlyPayment;
double balance;
double interestRate;
int month = 1;
cout.setf(ios::fixed); // These lines force currency format in output to 2 decimal pts
cout.setf(ios::showpoint);
cout.precision(2);
cout << "Enter the current balance of your loan: $";
cin >> balance;
cout << "Enter the interest rate (compounded monthly) : ";
cin >> interestRate;
cout << "Enter the desired monthly payment : $";
cin >> monthlyPayment;
while (interestRate >= 1)
{
interestRate = interestRate / 100;
}
balance = balance * (1 + interestRate / 12) - monthlyPayment;
// this is where the program stops.
cout << "After month 1 your balance is $" << balance << endl;
while (balance > 0)
{
balance = balance * (1 + interestRate / 12) - monthlyPayment;
month = month++;
cout << "After month " << month << ", your balance is : $" << balance << endl;
}
cout << "You have paid off the loan at this point. Congratulations!" << endl;
return 0;
|
When trying to get the program to reach the 1st output of what the balance is before the loop is initiated, it stops at line 27 and does not print the output from line 31. As of right now the output is:
Enter the current balance of your loan: $xxx.xx
Enter the interest rate (compounded monthly) : xx.xx
Enter the desired monthly payment : $xx
When enter is pressed after the user inputs the desired monthly payment, the program ends and closes out. I have only changed the code in deleting the ";"'s as informed but now rather I have them in or not, the program runs as said above and will not even print out the balance after calculation.
_______________________________________________________________
However, if I "Start without debugging", the program runs correctly. Any comments as to this occurrence?
Here is an example of output run when "start without debugging" is used.
Enter the current balance of your loan: $250
Enter the interest rate (compounded monthly) : 12.9
Enter the desired monthly payment : $50
After month 1 your balance is $202.69
After month 2, your balance is : $154.87
After month 3, your balance is : $106.53
After month 4, your balance is : $57.68
After month 5, your balance is : $8.30
After month 6, your balance is : $-41.61
You have paid off the loan at this point. Congratulations!
Press any key to continue . . .
I would like to keep from showing the line containing the balance when it goes negative but I do not know how to get a Boolean "range" to work within a while statement. I have attempted and the compiler will not build it.
Thanks again for your help and in advance to anyone else who does.
_