2015-02-10 42 views
0

我不知道我應該如何標題我的問題。我正試圖編寫一個程序,要求提供一個物業的價值。然後它將該值乘以60%來給出評估值。例如,如果一英畝土地的價值爲10,000美元,則其評估價值爲6,000美元。每100美元的評估價值,房產稅爲64美分。評估的6000英畝土地稅爲38.40美元。我必須設計一個模塊化程序,要求獲得一塊物業的實際價值,並顯示評估價值和物業稅。這是我到目前爲止。C#模塊數字輸入

{ 
    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美元。任何直接的答案或指南的鏈接,以便我可以自己修復它將不勝感激。

+0

在調用函數時,您以錯誤的順序發送參數。 – 2015-02-10 17:13:16

+0

當我調用函數時,什麼命令是正確的?我的命令對我有意義。獲得價值應該用例如10000代替0.0。然後稅應該採用屬性值的新值10000,並且計算出這兩種稅。然後showOutput應該把所有的值放在屏幕上。感謝您的幫助。 – redcell98 2015-02-10 17:54:04

回答

0

通常你不必使用所有這些參考資料。最好在靜態方法中返回一個值。

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; 
    } 

編輯: 在稅收方法,你不具備propertyTax論證的參考,你無法改變當前環境之外的價值。

+0

對不起,我只有三個星期到我的介紹編程課。我有一些問題,所以我可以確保我理解你的程序。在靜態方法GetAssessTax(double propertyValue)中。它是否告訴方法在GetAssessTax中的Main中爲propertyValue使用輸入?同樣在GetValue中,你是否在方法中再次聲明瞭propertyValue,然後它將輸入返回給main並覆蓋0.0? – redcell98 2015-02-10 17:47:35

+0

** 1)** 在您的代碼中,您更改了方法內部的變量,並返回了一個'void'類型。對 ?出於某些原因,這不是一個真正的好方法。 因此,我不會返回一個'void'類型,而是返回計算結果。所有的變量都在你的'Main'方法中。 ** 2)** Main和GetValue中的'propertyValue'不是相同的變量。 'GetValue'方法的'propertyValue'只存在於'GetValue'方法的本地上下文中,並且這個變量只存在於括號{}內。 你可以用不同的名字命名。 – 2015-02-10 18:03:42

+0

所以,當你返回propertyValue時,它返回並在做什麼?我認爲它正在返回到Main並更改相同名稱的變量。 – redcell98 2015-02-10 18:20:35