0

我不确定我应该如何命名我的问题。我正在尝试编写一个询问属性值的程序。然后它取该值并将其乘以 60% 以给出评估值。例如,如果一英亩土地的价值为 10,000 美元,则其评估价值为 6,000 美元。每 100 美元的评估价值需缴纳 64 美分的财产税。评估为 6,000 美元的一英亩土地的税为 38.40 美元。我必须设计一个模块化程序,询问一块财产的实际价值并显示评估价值和财产税。这是我到目前为止所拥有的。

{
    static void Main(string[] args)
    {
        double propertyValue = 0.0;
        double assessTax = 0.0;
        double propertyTax = 0.0;

        getValue(ref propertyValue);
        Tax(ref propertyValue, propertyTax, assessTax);
        showOutput(ref propertyTax, assessTax, propertyValue);

    }///End Main
    static void showOutput(ref double propertyValue, double assessTax, double propertyTax)
    {
        Console.WriteLine("Your Entered Property Value was {0, 10:C}", propertyValue);
        Console.WriteLine("Your Assessment Value is {0, 10:C}", assessTax);
        Console.WriteLine("Your Property Tax is {0, 10:C}", propertyTax);
    }///End showOutput
    static void getValue(ref double propertyValue)
{
    Console.WriteLine("Please Enter Property Value");
    while (!double.TryParse(Console.ReadLine(), out propertyValue))
        Console.WriteLine("Error, Please enter a valid number");
}///End getValue
 static void Tax(ref double propertyValue, double assessTax, double propertyTax)
{
    assessTax = propertyValue * 0.60;
    propertyTax = (assessTax / 100) * 0.64;
}///End Tax

这是我第一次尝试在 Dreamspark 中写任何东西,所以如果答案很明显,我深表歉意(我有点迷路了)。我在想也许我对财产价值的输入没有被保存。当我尝试运行它时,我得到的财产价值是 0.00 美元,评估价值是 0.00 美元,财产税是 10,000 美元。任何直接的答案或指向指南的链接,以便我自己修复它,我们将不胜感激。

4

1 回答 1

0

通常你不必使用所有这些 ref 的东西。最好只在静态方法中返回一个值。

    static void Main(string[] args)
    {
        double propertyValue = 0.0;
        double assessTax = 0.0;
        double propertyTax = 0.0;

        propertyValue = GetValue();
        assessTax = GetAssessTax(propertyValue);
        propertyTax = GetTax(assessTax);

        ShowOutput(propertyValue, assessTax, propertyTax);

        Console.ReadKey(true);

    }

    static void ShowOutput(double propertyValue, double assessTax, double propertyTax)
    {
        Console.WriteLine("Your Entered Property Value was {0, 10:C}", propertyValue);
        Console.WriteLine("Your Assessment Value is {0, 10:C}", assessTax);
        Console.WriteLine("Your Property Tax is {0, 10:C}", propertyTax);
    }

    static double GetValue()
    {
        double propertyValue;

        Console.WriteLine("Please Enter Property Value");
        while (!double.TryParse(Console.ReadLine(), out propertyValue))
            Console.WriteLine("Error, Please enter a valid number");

        return propertyValue;
    }

    static double GetAssessTax(double propertyValue)
    {
        return  propertyValue * 0.60;
    }

    static double GetTax(double assessTax)
    {
        return (assessTax / 100) * 0.64;
    }

编辑:在您的 Tax 方法中,您没有 propertyTax 参数的引用,您无法在当前上下文之外更改值。

于 2015-02-10T17:13:00.647 回答