C語言还款程序问题
#include <stdio.h>#include <math.h>
double round2 (double);
int main ()
{
// Local Declaration
int NM;
double IM, P, Q, MP, IY, NY, PR;
// Statements
printf("The amount of the loan (principal) :");
scanf("%lf", &PR);
printf("Interest rate / year (per cent) :");
scanf("%lf", &IY);
printf("Number of Years :");
scanf("%lf", &NY);
NM = NY*12;
IM = IY / 12 / 100;
P = pow((1+IM),NM);
Q = (P/(P-1));
MP = PR * IM * Q;
printf("Interest rate / month (decimal) : %lf\n", IM);
printf("Number of Months : %d\n", NM);
printf("Monthly payment : %lf\n", MP);
int Month;
double OldBalance, MonthlyPayment, Interestpaid, Principalpaid, NewBalance;
OldBalance = PR - NewBalance;
MonthlyPayment = MP;
Interestpaid = OldBalance * IM;
Principalpaid = MP - (OldBalance * IM);
NewBalance = OldBalance - Principalpaid;
printf("\n Old Monthly Interestpaid Principal New");
printf("\nMonth Banlace Payment paid paid Balance\n");
printf("===== ========= ========= ========= ========= =========\n");
for(Month=1;Month<=12;Month++)
printf(" %d %lf %lf %lf %4lf %4lf\n", Month, OldBalance, MonthlyPayment, Interestpaid, Principalpaid, NewBalance);
这样写,它不会循环计算啊,直接给我一大堆负数
怎么写才能让输入的金额一直循环计算到0啊???求救啊大神
还有写了round2 printf出来的数字怎么不是两位小数的?