C#教学经验谈(3):储蓄计算器的源程序__教程 |
|
日期:2007-5-20 1:27:08 人气:76 [大 中 小] |
|
|
|
this.ResumeLayout(false);
} #endregion
/// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.Run(new Form1()); }
private void 计算_Click(object sender, System.EventArgs e) { double startAmount=(double)初始金额.Value; double rate=(double)利率.Value; int years=(int)存期.Value; Compound calcFrequency=(Compound) 计算规则.SelectedItem; double additional=(double)每月存入.Value;
decimal totalValue=0; rate=rate/100;
int months=12*years;
switch (calcFrequency) { case Compound.每月计算利息: double monthlyRate=rate/12; for (int i=1; i<=months; i++) { startAmount+=startAmount*monthlyRate; startAmount+=additional; } break; case Compound.每季度计算利息: double quarterlyRate=rate/4; for (int i=1; i<=months; i++) { if (i%3==0) { startAmount+=startAmount*quarterlyRate; } startAmount+=additional; } break; default: MessageBox.Show("该项工作尚未实现!"); break; } totalValue=(decimal)startAmount; 存款总额.Value=totalValue; } } }
|
|
出处:本站原创 作者:佚名 |
|
|