C語言及程式設計 實踐參考——定期存款利息計算器
阿新 • • 發佈:2018-11-16
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
【專案:定期存款利息計算器】
輸入存款金額並選擇存款種類,計算出利息(不計利息稅)和本息合計。要求使用switch語句,根據選擇的存款種類,確定利率和存期後計算。
提示:利息=金額×年利率×存期(單位:年,3個月為0.25年,6個月為0.5年)。
例如:1000元存6個月,利息=1000×0.033×0.5=16.5元
利率使用2011年7月7日公佈的年利率:3個月 3.10%,6個月 3.30%,一年 3.50%,二年 4.40%,三年 5.00%,五年 5.50%。
程式執行圖參考下面的介面:
[參考解答]
#include <stdio.h>int main ( ){ int type; double money, period, rate, interest; printf("歡迎使用利息計算器!\n"); printf("請輸入存款金額:"); scanf("%lf", &money); printf("======存款期限======\n" ); printf("1. 3個月 \n"); printf("2. 6個月\n"); printf("3. 一年 \n"); printf("4. 二年\n"); printf("5. 三年\n"); printf("6. 五年\n"); printf("請輸入存款期限的代號:"); scanf("%d", &type); if (type>=1 && type <=6) { switch(type) //在if中嵌入了switch分情況處理 { case 1: period = 0.25; rate = 0.031; break; case 2: period = 0.5; rate = 0.033; break; case 3: period = 1; rate = 0.035; break; case 4: period = 2; rate = 0.044; break; case 5: period = 3; rate = 0.05; break; case 6: period = 5; rate = 0.055; break; } interest = money * period * rate; printf("到期利息為:%.2lf 元,本息合計共 %.2lf 元。\n", interest, interest + money); } else printf("選擇存款型別錯誤!\n"); printf("感謝您的使用,歡迎下次光臨!\n"); return 0;}