band

 1 #include<iostream>
 2 #include<math.h>
 3 using namespace std;
 4 int calculate(double amount[],int year,double rate,double in[],double p[],double* m,double * t)
 5 {
 6     double mon,tot,mr;
 7     int mm,k;
 8     mm = year * 12;
 9     mr = rate / mm;
10     m = & mon;
11     t = & tot;
12     mon = amount[0] * mr* pow(1+mr,mm) / (pow(1+mr,mm) - 1);
13     tot = mon * mm ;
14     for(k = 1;k <= mm ; k++)
15     {
16         in[k] = amount[k-1] * mr;
17         p[k] = mon-in[k];
18         amount[k] = amount[k-1]-p[k];
19     }
20     return 0;
21 }
22 int main()
23 {
24     double amount[100];
25     int year,k,l;
26     double * m,* t,a,b;
27     double rate;
28     double in[100],p[100];
29     m=&a;
30     t=&b;
31     cout<<"Please input load amount,the number of years and the annual interest rate: "<<endl;
32     cin>>amount[0]>>year>>rate;
33     l = year*12;
34     calculate(amount,year,rate,in,p,m,t);
35     cout<<"Load Amount: "<<amount[0]<<endl;
36     cout<<"Number of Years: "<<year<<endl;
37     cout<<"Annual Interest Rate: "<<rate<<endl;
38     cout<<"Monthly Payment: "<<a<<endl;
39     cout<<"Total Payment: "<<b<<endl;
40     cout<<"Payment#            Interest        Principal        Balance"<<endl;
41     for(k=1;k <= l;k++)
42         cout<<k<<"        "<<in[k]<<"        "<<p[k]<<"        "<<amount[k]<<endl;
43     return 0;
44 }

 

posted on 2013-12-26 16:47  了发发  阅读(205)  评论(0)    收藏  举报

导航