该法典应当从用户那里获得有关家庭贷款细节的投入,并计算他们在贷款期间将支付多少费用。 我的《守则》适当吸收了所有投入,但以我“为”的回旋方式印刷这些投入。 我的“Month”变量被定在令人难以置信的高位,其余则定在0。 如何使我的守则适当发挥作用
我预计会拿到贷款余额的所有投入,从业者,每个月支付多少款项,以及年数。 然后,将计算为总余额和利息支付金额支付的款项,并在最后月份之前每个月印出,届时将支付全部款项和现余额。
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int years, month, final_month, annual_interest_rate;
double loan_balance, interest_for_this_month, monthly_payment, total_interest, leftover_payment, monthly_interest_rate;
printf("
Loan Amount = ");
scanf("%lf", &loan_balance);
printf("%.2lf
", loan_balance);
printf("
Number of Years = ");
scanf("%i", &years);
printf("%i
", years);
printf("
Annual Interest Rate Percent = ");
scanf("%i", &annual_interest_rate);
printf("%i
", annual_interest_rate);
printf("
Monthly Payment = ");
scanf("%.2lf", &monthly_payment);
printf("%.2lf
", monthly_payment);
monthly_interest_rate = annual_interest_rate/1200;
final_month = years*12;
//total_interest = 0;
for(month = 1; month <= final_month; month = month+1)
{
interest_for_this_month = (monthly_interest_rate * loan_balance);
total_interest = (total_interest + interest_for_this_month);
leftover_payment = (monthly_payment - interest_for_this_month);
loan_balance = (loan_balance - leftover_payment);
printf("Month = (%i), This month s interest = (%.2lf) leftover payment = (%.2lf) Loan Balance = (%.2lf
)"); month, interest_for_this_month, leftover_payment, loan_balance;
}
printf("
Total Interest = %.2lf
", total_interest);
printf("Final Loan Balance = %.2lf
", loan_balance);
return 0;
}