Can't get anything but $0 from a call to a method to calculate a taxAmount

前端 未结 5 504
-上瘾入骨i
-上瘾入骨i 2021-01-22 11:00

I am having trouble with this following call, specially the last component:

Console.WriteLine(\"Taxpayer # {0} SSN: {1}, Income is {2:c}, Tax is {3:c}\", i + 1,          


        
5条回答
  •  心在旅途
    2021-01-22 11:33

    No-repro. Using the simple program below, I get valid non-zero result (900 using my values):

    internal class Program {
        private static int incLimit = 30000;
        private static float lowTaxRate = 0.18F;
        private static float highTaxRate = 0.30F;
    
        private static void Main(string[] args) {
            var result = CalculateTax(5000);
        }
    
        public static int CalculateTax(int income) {
            int taxOwed;
            // If income is less than the limit then return the tax
            //   as income times low rate.
            if (income < incLimit) {
                taxOwed = Convert.ToInt32(income * lowTaxRate);
            }
            // If income is greater than or equal to the limit then
            //   return the tax as income times high rate.
            else if (income >= incLimit) {
                taxOwed = Convert.ToInt32(income * highTaxRate);
            }
            else taxOwed = 0;
    
            return taxOwed;
        }
    }
    

提交回复
热议问题