2012-12-07 23 views
0

我正在研究計算所得稅的模塊化程序。在我的腦海中,它是有道理的,但我的程序只運行一行代碼,然後停止...沒有錯誤信息沒有任何東西。我有一種感覺它有事情做,在我CalculateTaxDue類while循環模塊化程序故障。只運行一行(沒有錯誤消息.____。)

程序有: 一)從用戶獲得有效輸入(一類) B)計算到期的稅收(以另一類) c)顯示用戶輸入的應納稅所得額,按統一稅率計算的應納稅額,按可變百分比計算的應納稅額和應納稅總額(在另一類別中)

這裏是我的計劃到目前爲止。我覺得它應該正常運行,但它不會。

class Program 
{ 
    static void Main(string[] args) 
    { 
     // declare variables 
     double taxableIncome, incomeTaxDue, flatRate, variablePercentage; 

     // get user input 
     taxableIncome = GetTaxableInput.GetDouble("Please enter your total income: "); 

     // calculate tax due 
     incomeTaxDue = CalculateTaxDue.GetTaxableIncome(taxableIncome); 

     // display taxable income 
     DisplayTaxRate.DisplayTaxableIncome("Your total income is: ", taxableIncome); 

     // display flat rate 
     flatRate = CalculateTaxDue.GetFlatRate(taxableIncome); 
     DisplayTaxRate.DisplayFlatRate("Your tax rate is: ", flatRate); 

     // display variable percentage 
     variablePercentage = CalculateTaxDue.GetVariablePercentage(taxableIncome); 
     DisplayTaxRate.DisplayVariablePercentage("Your variable percentage is: ", variablePercentage); 

     // display total tax due 
     DisplayTaxRate.DisplayTotalTaxDue("Your total income tax due is: ", incomeTaxDue); 

     // keep console open 
     Console.ReadLine(); 
    } 
} 

class GetTaxableInput 
{ 
    public static double GetDouble(string message) 
    { 
     // declare variable 
     double result; 
     // ask for input 
     Console.Write(message); 
     // capture and validate the user input 
     while (!double.TryParse(Console.ReadLine(), out result)) 
     { 
      Console.WriteLine("Invalid input "); 
      Console.Write(message); 
     }; 
     return result; 
    } 
} 

class CalculateTaxDue 
{ 
    public static double GetTaxableIncome(double taxableIncome) 
    { 
     double incomeTaxDue; 
     double flatRate; 
     double variablePercentage; 

     // calculate and return total income tax due. 
     while (!double.TryParse(Console.ReadLine(), out incomeTaxDue)) 
     { 

      if (taxableIncome < 0) 
      { 
       flatRate = 0; 
       variablePercentage = 0; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome < 49999) 
      { 
       variablePercentage = 0.05; 
       flatRate = 0; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome < 99999) 
      { 
       variablePercentage = 0.07; 
       flatRate = 2500; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome > 100000) 
      { 
       variablePercentage = 0.09; 
       flatRate = 6000; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
     } 
     return incomeTaxDue; 
    } 

    // calculate and return the tax rate 
    public static double GetFlatRate(double taxableIncome) 
    { 
     double incomeTaxDue; 
     double flatRate; 
     double variablePercentage; 

     while (!double.TryParse(Console.ReadLine(), out flatRate)) 
     { 

      if (taxableIncome < 0) 
      { 
       flatRate = 0; 
       variablePercentage = 0; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome < 49999) 
      { 
       variablePercentage = 0.05; 
       flatRate = 0; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome < 99999) 
      { 
       variablePercentage = 0.07; 
       flatRate = 2500; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome > 100000) 
      { 
       variablePercentage = 0.09; 
       flatRate = 6000; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
     } 
     return flatRate; 
    } 

    // calculate and return the variable percentage (tax rate) 
    public static double GetVariablePercentage(double taxableIncome) 
    { 
     double incomeTaxDue; 
     double flatRate; 
     double variablePercentage; 

     while (!double.TryParse(Console.ReadLine(), out variablePercentage)) 
     { 

      if (taxableIncome < 0) 
      { 
       flatRate = 0; 
       variablePercentage = 0; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome < 49999) 
      { 
       variablePercentage = 0.05; 
       flatRate = 0; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome < 99999) 
      { 
       variablePercentage = 0.07; 
       flatRate = 2500; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
      else if (taxableIncome > 100000) 
      { 
       variablePercentage = 0.09; 
       flatRate = 6000; 
       incomeTaxDue = taxableIncome * variablePercentage + flatRate; 
      } 
     } 
     return variablePercentage; 
    } 
} 

class DisplayTaxRate 
{ 
    public static void DisplayTaxableIncome(string message, double numberValue) 
    { 
     Console.WriteLine("{0} {1:c}", message, numberValue); 
    } 
    public static void DisplayFlatRate(string message, double numberValue) 
    { 
     Console.WriteLine("{0} {1:c}", message, numberValue); 
    } 
    public static void DisplayVariablePercentage(string message, double numberValue) 
    { 
     Console.WriteLine("{0} {1:P}", message, numberValue); 
    } 
    public static void DisplayTotalTaxDue(string message, double numberValue) 
    { 
     Console.WriteLine("{0} {1:c}", message, numberValue); 
    } 
} 

它在那裏。就像我之前說的,我沒有收到任何錯誤信息,所以我不知道從哪裏開始。 謝謝!

+3

您是否嘗試過在調試模式下執行代碼? –

+0

您需要更清楚地瞭解該程序的作用與您期望的不同。它是否產生任何輸出?它是否給出了接受你試圖給予的輸入的任何跡象? – antlersoft

+0

您發佈的代碼無用 - 我們需要查看未終止的代碼。在調試器中瀏覽程序或添加一些調試日誌記錄語句將幫助您找到問題區域。 – Lee

回答

0

我想通了。由於某種原因,我有一段時間的循環讓我的計算課得到輸入:/感謝Chris Dunaway!現在就像魅力一樣。