Search code examples
c#moduledreamspark

C# Modules Numerical Inputs


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.


Solution

  • 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.