0

I wasn't sure how I should title my problem. I am attempting to write a program that asks for the value of a property. It then takes the value and multiplies it by 60% to give the assessment value. For example if an acre of land is valued at $10,000, its assessment value is $6,000. Property tax is 64 cents for every $100 of the assessment value. The tax for an acre of land assessed at $6,000 will be $38.40. I have to design a modular program that asks for the actual value of a piece of property and displays the assessment value and property tax. Here is what I have so far.

{
    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

This is my first attempt at writing anything in dreamspark so I apologize if the answer is obvious (I'm kinda lost). I'm thinking maybe my input for property value is not being saved. When I try running it I get property value is $0.00, assessment value is $0.00 and property tax is $10,000. Any direct answers or links to a guide so that I can fix it myself will be appreciated.

redcell98
  • 13
  • 5
  • While calling functions you are sending parameters in wrong order. – Orkun Bekar Feb 10 '15 at 17:13
  • When I am calling the functions what order would be correct? The order I had made sense to me. Get value should replace the 0.0 with for example 10000. Tax should then take the new value of property value, 10000, and figure out the two taxes. Then showOutput should put all the values on the screen. Thank you for your help. – redcell98 Feb 10 '15 at 17:54

1 Answers1

0

Usually you do not have to use all this ref stuff. It's better to just return a value in your static methods.

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

EDIT : In your Tax method, u don't have the reference of the propertyTax argument, u can't change the value outside the current context.

  • Sorry, I'm only three weeks into my intro programming class. I had some questions so that I can make sure I understand your program. In the static method GetAssessTax(double propertyValue). Is it telling the method to use the input in the Main for propertyValue in GetAssessTax? Also in GetValue, did you declare propertyValue again inside the method and then it returns the input back to the main and overwrites the 0.0? – redcell98 Feb 10 '15 at 17:47
  • **1)** In your code, you changed variables inside the methods and you returned a `void` type. Right ? For some reasons, this is not really a good way to do this. So instead of returning a `void` type, I return the results of your calculations. And all variables changes are in your `Main` method. **2)** `propertyValue` in the Main and in the `GetValue` are NOT the same variables. `propertyValue` of the `GetValue` method exists ONLY in the local context of the `GetValue` method and this variable lives just inside the brackets { }. You could name both with a different name. – Quentin Baradat Feb 10 '15 at 18:03
  • So when you return propertyValue, where is it returning to and doing? I thought that it was returning to the Main and changing the variable of the same name. – redcell98 Feb 10 '15 at 18:20
  • `GetValue` returns just a value (a double). There is not references, or pointers stuff. In the `Main `method, `double propertyValue = 0.0;` takes this value here `propertyValue = GetValue();`. I mean that if you replace `GetValue();` by any double value (10.0, 13.7, ...) , it's the "same idea". Or if you create a new method `static double GetValue() { return 14.5; }`, it's also the "same idead". I'm not sure of being understood :p – Quentin Baradat Feb 10 '15 at 19:35
  • I just started so I don't know all the vocabulary yet but I believe I am starting to understand what a return statement is doing. GetValue is just returning the result of the method to the caller, which I think is property value = GetValue(); – redcell98 Feb 10 '15 at 20:16