如何将输出显示

时间:2015-04-23 23:36:28

标签: c

我正在尝试让输出显示付款和余​​额。

input.equalsIgnoreCase("y")

2 个答案:

答案 0 :(得分:1)

我在代码中发现了一些错误,在这里我没有提到你使用的逻辑,只是编码错误。

  1. scanf("%i",& loan_amount),此处%i 应更改为%f ,因为loan_amount是浮动。
  2. while(loan_amount> 0; 是语法错误,它应该是而(loan_amount> 0){
  3. 请将 interest = loan_amount rate / 12; *更改为 interest = loan_amount rate / 12.0; *,某些编译器会在整数值时将浮动结果截断为整数用于分裂。

答案 1 :(得分:0)

试试这个,我评论了我改变的行

#include <stdio.h>
int main (void)
{    
 float loan_amount, rate, payment, monthly_amount, interest;
 int t, i=1;
 printf("Enter Loan Amount");

 scanf("%f", &loan_amount); // changed %i to %f since loan_amount is a float

 printf("Enter Interest rate:");
 scanf("%f", &rate);
 printf("Enter Monthly Payment:");
 scanf("%f", &payment);
 printf("Enter number of payments:");
 scanf("%d",&t);
 while(loan_amount>0) //Changed ; to )
 {
      interest = loan_amount*rate/12;
      monthly_amount = (loan_amount+interest - payment);
      if(monthly_amount>0)
           printf("Balance remaing after %d payment: $ %.2f\n",i, monthly_amount);
      loan_amount = monthly_amount;
      i++;
 }
 return 0;
}