| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1530 人关注过本帖
标题:C語言还款程序问题
取消只看楼主 加入收藏
zzy95621
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2016-10-26
结帖率:100%
收藏
 问题点数:0 回复次数:2 
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出来的数字怎么不是两位小数的?
搜索更多相关主题的帖子: principal include double amount 
2016-11-01 21:24
zzy95621
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2016-10-26
收藏
得分:0 
回复 3楼 炎天
其他的通过自己努力搞定了。
只是for那一部分,
能不能让这个for无限循环
只有满足NewBalance<=0 然后用 IF  这个指令让停止循环
2016-11-02 00:09
zzy95621
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2016-10-26
收藏
得分:0 
回复 5楼 炎天
这是我自己写好的
看这个比较好
我尝试了for(Month=1;NewBalance>0;Month++)
输入1000, 10, 0.5
第七个月能不显示?

#include <stdio.h>
#include <math.h>
double round2 (double);
int main ()
{

printf("Assignment - chung chun yu, EG114402-1C, 160224757\n");
     // 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("The amount of the loan (principal) : %.2lf\n", PR);
     printf("Interest rate / month (decimal) : %lf\n", IM);
     printf("Number of Months : %d\n", NM);
     printf("Monthly payment : %.2lf\n", MP);


     int Month;
     double OldBalance, MonthlyPayment, Interestpaid, Principalpaid, NewBalance;

{


        OldBalance        = PR;
        NewBalance        = PR - Principalpaid;
        MonthlyPayment    = MP;
        Interestpaid      = OldBalance * IM;
        Principalpaid     = MP - (OldBalance * IM);


printf("\n            Old          Monthly      Interestpaid     Principal        New");
printf("\nMonth     Banlace        Payment        paid            paid          Balance\n");
     printf("=====    =========      =========     =========       =========      =========\n");

}

for(Month=1;Month<=12;Month++)
{

        OldBalance        = NewBalance;
        NewBalance        = OldBalance - Principalpaid;
        MonthlyPayment    = MP;
        Interestpaid      = OldBalance * IM;
        Principalpaid     = MP - (OldBalance * IM);



     printf(" %d        %.2lf\t%.2lf     \t%.2lf    \t%.2lf    \t%.2lf\n", Month, OldBalance, MonthlyPayment, Interestpaid, Principalpaid, NewBalance);

}
 }
      double round2 (double x)
     {
         long xInt;
         double result;

         xInt   = (int)(x*100+0.5);
         result = (double)xInt/100;
         return result;
     }



  

[此贴子已经被作者于2016-11-2 00:21编辑过]

2016-11-02 00:19
快速回复:C語言还款程序问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012374 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved