the code you have is way too simplistic. avoid using static values (like 1000) make everything variables from the start.
Initialise all variables when they are declared (or at least before you use them)
e.g. float mp=0.0f,chrg=0;
the interest charge needs to be recalculated every loop on the remaining balance.
There are several ways to do this code, here's one suggestion
Code:
float mp=0,chrg=0;
float balance=1000;
float interest_rate=1.5;
float total_payments=0;
cin>>mp;
for(;;){
// add 1.5% to balance
balance+=(balance/100)*interest_rate;
// calculate new balance after payment
balance-=mp;
// recalculate total payments
total_payments+=mp;
// output new balance
cout<<balance<<"\n";
// validate new balance
if(balance<=0) break;
}
cout <<"End.\n";
as for the improved program...
you need to test when a monthly payment will take the balance below zero, break there instead of subtracting, and work out the amount to pay on the last installment to bring the balance to zero.
As this is an excercise i've resisted the temtation to write the whole thing properly. You won't learn anything if people do it for you....