vendredi 2 août 2019

Use of unassigned local variable? Can someone explain?

I'm new to writing codes, I understand a few but I can't make some things work.

I want this to make the user choose a category first before giving them access to one but I get the error saying "use of the unassigned local variable". Did I do something wrong?

    public static void Main(string[] args)

    {
        bool CalculateSavings, Grades;
        if (CalculateSavings == true)
        {
            int MySavings, Allowance, Food, Transportation, WeeklySavings, MonthlySavings;

            Console.WriteLine("Input your daily allowance:");
            Allowance = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Input your daily food expenses:");
            Food = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Input your daily transportation expenses:");
            Transportation = Convert.ToInt32(Console.ReadLine());

            {

                MySavings = Allowance - (Food + Transportation);
                Console.WriteLine("Your calculated daily savings: {0}", MySavings);

                WeeklySavings = MySavings * 5;
                Console.WriteLine("Your calculated weekly savings: {0}", WeeklySavings);

                MonthlySavings = WeeklySavings * 4;
                Console.WriteLine("Your calculated monthly savings: {0}", MonthlySavings);

                Console.ReadKey();
            }


        }
        else if (Grades == true)
        {
            double Filipino, English, Science, Math, History, Average;

            Console.WriteLine("Input grade in Filipino subject:");
            Filipino = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Input grade in English subject:");
            English = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Input grade in Science subject:");
            Science = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Input grade in Math subject:");
            Math = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Input grade in History subject:");
            History = Convert.ToDouble(Console.ReadLine());

            Average = (Filipino + English + Science + Math + History) / 5;
            Console.WriteLine("Overall grade average: {0}", Average);
            Console.ReadLine();

        }
    }
}

}

Make the user choose a category first before giving them access to one but I get the error saying "use of the unassigned local variable".

Aucun commentaire:

Enregistrer un commentaire