【C#】 迴圈小練習_ 條件分支應用 所得稅計算

  • 983
  • 0
  • C#
  • 2020-04-15

條件分支應用 所得稅計算 (所得稅率基準為2020年)

這是一個很典型的條件分支應用題,假設全年應納稅額屬於 i 等級。

應繳納稅款 = 前 i - 1 級累加稅款 + 目前等級超出部分 x 目前等級稅率。

class Program
    {
        static void Main(string[] args)
        {
            //條件分支應用 所得稅率
            //2020 稅率計算 

            Console.Write("請輸入個人收入:");
            int num = Convert.ToInt32(Console.ReadLine());//設定個人收入


            decimal g = GetTax(num);
            int tax = Convert.ToInt32(Math.Round(g, 0));

            Console.WriteLine("應繳金額為:{0}", tax);
            Console.ReadLine();
        }


        public static decimal GetTax(int num)
        {
            int tax = 0;
            int tt = 0;
            int[] ra = { 0, 540000, 1210000, 2420000, 4530000, 10310000 };
            int[] rate = { 5, 12, 20, 30, 40, 45 };

            int x = 88000; //免稅額+
            int y = 90000; //標準扣除額
            int z = 20000; //薪資所得扣除額         //其他特別扣除不討論 ..
            //所得淨額 = 所得總額 + 免稅額 + 一般扣除(列舉扣除) - 特別扣除額
            int tx = num - x - y - z;
            Console.WriteLine("所得淨額為:{0}", tx);
            
            //取得所得淨額級距
            int idx = 0;
            for (int i = 0; i < ra.Length; i++)
            {
                if (tx < ra[i])
                {
                    idx = i;
                    break;
                }
            }

            Console.WriteLine("所得級距在 {0} 級:", idx);
            
            //計算累進差額
            int dtax = 0;
            for (int j = 0; j < idx - 1; j++)
            {
               
                dtax = dtax + Convert.ToInt32((ra[j + 1] - ra[j]) * (rate[idx-1] - rate[j]) * 0.01);

             }
            Console.WriteLine("累進差額: {0}", dtax);
            
            //計算應繳所得
            tax = Convert.ToInt32(tx * rate[idx - 1] * 0.01) - dtax;
            return tax;
        }


圖片擷取來源為:Money101.com.tw 

 

水滴可成涓流,涓流可成湖泊大海。
汲取累積知識,將知識堆積成常識;將常識探究成學識;將學識簡化為知識;授人自省。