C# 模块数字输入

C# Modules Numerical Inputs

我不确定应该如何命名我的问题。我正在尝试编写一个程序来询问 属性 的值。然后它取值并将其乘以 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 美元。任何直接的答案或指向指南的链接都将不胜感激,以便我自己修复它。

通常您不必使用所有这些参考资料。最好只 return 静态方法中的值。

    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 参数的引用,您无法更改当前上下文之外的值。