iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 28
1
Software Development

C#可以做出甚麼?系列 第 28

倒數第3天

  • 分享至 

  • xImage
  •  

大家安安/images/emoticon/emoticon24.gif

突然發現有人關注
但是~/images/emoticon/emoticon25.gif
前面的坑還沒有補好
後面很難寫
不過這篇我預計會寫"算利息"因為"人生第一次忘記繳錢"/images/emoticon/emoticon20.gif

還好只過了一天..沒被罰錢


using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace BA993265_2

{

class Program

{

static void Main(string[] args)

        {

            {

                string[] monthStr = new string[] { "一", "二", "三", "四", "五" };

                int month = 0;

                double loan = 0.0, pay = 0.0, total = 0.0;

                double interest = 0.0;//利息

                double interestTotal = 0.0;

                double tax = 0.18;//年利率

                double tot_interest = 0.0;//利息總額

                while (true)

                {

                    Console.Write("\n請輸入您向銀行的借款金額:");

                    loan = Convert.ToDouble(Console.ReadLine());//將輸入的資料轉成整數

                    total = loan;

                    Console.Write("請輸入您每月還款的金額");

                    pay = Convert.ToDouble(Console.ReadLine());//將輸入的資料轉整數

                    if (pay > loan)

                    {

                        Console.Write("\n每月還款不能大於 借款!\n");

                        continue;

                    }

                    break;

                }

                while (loan > 0)

                {

                    interest = (loan * tax) / 12;//每月應還的利息

                    if ( loan - pay > 0 )

                    {

                        loan -= pay;                        

                        loan += interest;

                    }

                    month++;                    

                    

                    Console.WriteLine("第{0}個月底,利息等於{1:C},尚欠{2:C}", monthStr[month-1], interest, loan);

                    if (loan - pay < 0)

                    {

                        interest = loan * tax / 12;

                        loan += interest;

                        month++;

                        Console.WriteLine("第{0}個月底,利息等於{1:C},最後還款{2:C}", monthStr[month - 1], interest, loan);

                        loan = 0;                        

                    }

                    interestTotal += interest;

                }

                Console.WriteLine("您借{0},還了{1}個月,利息共還{2:C}.\n\n", total, month, interestTotal);

                Console.Read();

            }

        }


DEAR ALL 我們明天見 /images/emoticon/emoticon06.gif


上一篇
倒數第4天
下一篇
倒數第2天
系列文
C#可以做出甚麼?30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言