### Need help getting my loan calculator to loop

I am having a lot of trouble getting my loan calculator to loop. My program is meant to prompt a user for some info, do some calculations, and create an amortization table telling the user how much they will have to pay each month in order to pay off their loan in the allotted time. My issue is that the program goes through successfully once, but just repeats itself with all the same info. More specifically, if the initial balance of the loan is 5000.00, and the new balance after a payment is 4500.00, instead of my program having a starting balance of 4500.00 the next month, it just starts at 5000.00 again. Can I get any help with this? Here is my code:
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950`` ``````#include #include #include using namespace std; int main(){ float Principal; float Interest; float Months; float AccInterest; float monPayment; float appPrincipal; float endBalance; cout << "Welcome to the loan calculator!" << endl; cout << "Please enter the amount of your loan: "; cin >> Principal; cout << "Please enter the interest rate: "; cin >> Interest; cout << "Finally, please enter the amount of months the loan is for: "; cin >> Months; AccInterest = (Principal) * (Interest/100)/12; monPayment = (Principal * (Interest/100)/12) * (pow(1+(Interest/100)/12, Months) / (pow(1+(Interest/100)/12, Months) -1)); appPrincipal = monPayment - AccInterest; endBalance = Principal - monPayment + AccInterest; for(Months = 1; Months <=48; Months++){ cout << Months << endl; cout << "Starting Principal: \$" << Principal << endl; cout << "Payment is: \$" << monPayment << endl; cout << "Accured interest is: \$" << AccInterest << endl; cout << "Applied to Principal is: \$" << appPrincipal << endl; cout << "End balance: \$" << endBalance << endl;} return 0;} ``````

it's a very difficult language.....
@GamerDJX

For one, the variables were never changed inside your loop, plus you have a loop that is set at 48, not how many months the user enters. Here is your program with the variables moved to inside the loop and the loop to user inputted months. You still have a problem with your loan payment amounts, etc. When a loan is paid in installments, it should be paid off at the end of the period. That formula is something you'll have to find out.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243`` ``````#include #include #include using namespace std; int main() { float Principal; float Interest; int Months; float AccInterest; float monPayment; float appPrincipal; float endBalance; cout << "Welcome to the loan calculator!" << endl; cout << "Please enter the amount of your loan: "; cin >> Principal; cout << "Please enter the interest rate: "; cin >> Interest; cout << "Finally, please enter the amount of months the loan is for: "; cin >> Months; for(int x = 0; x < Months; x++) // No matter what user entered for months, You still had 48. Changed it. { AccInterest = (Principal) * (Interest/100)/12; monPayment = (Principal * (Interest/100)/12) * (pow(1+(Interest/100)/12, Months) / (pow(1+(Interest/100)/12, Months) -1)); appPrincipal = monPayment - AccInterest; endBalance = Principal - monPayment + AccInterest; cout << "Month " << x+1 << " of " << Months << endl; cout << "Starting Principal: \$" << Principal << endl; cout << "Payment is: \$" << monPayment << endl; cout << "Accured interest is: \$" << AccInterest << endl; cout << "Applied to Principal is: \$" << appPrincipal << endl; cout << "End balance: \$" << endBalance << endl; Principal -= appPrincipal; } return 0; }``````
Topic archived. No new replies allowed.