模块化程序的麻烦。只运行一行(没有错误消息.____。)

时间:2012-12-07 22:36:25

标签: c# debugging module

我正在制定计算所得税的模块化计划。在我的脑海里它是有道理的,但我的程序只运行一行代码然后停止...没有错误消息没有任何东西。我觉得它与我的CalculateTaxDue类中的while循环有关

该计划必须: a)从用户那里获得有效的输入(在一个班级中) 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);
    }
}

就是这样。就像我之前说过的,我没有收到任何错误消息,所以我不知道从哪里开始。 谢谢!

1 个答案:

答案 0 :(得分:0)

我明白了。由于某种原因,我有一个while循环来获取计算类中的输入:/感谢Chris Dunaway!现在就像一个魅力。