I have a problem that I have been trying to sort out for quite a while now but I just can't wrap my head around it. I have two double variables that are initialized. Obviously, I get an error for that because they should have a value. However, the only value I could set it to is 0. The issue with that is, if I set the value to 0, my program does not run correctly and the output of my program becomes 0 too.
Error: Local variable 'userSalary' might not be initialized before accessing
I am still kind of learning the ways of methods, parameters, and arguments.
class Program { static void Main(string[] args) { double userSalary; double leftOver; AskQuestion(userSalary); CalculateTax(userSalary, leftOver); } static void AskQuestion(double userSalary) { Console.WriteLine("What is annual your salary?"); userSalary = Convert.ToDouble(Console.ReadLine()); } static void CalculateTax(double userSalary, double leftOver) { if (userSalary <= 14_000) //10% { Console.WriteLine("You are in Tax Category 1. 10% of your Salary goes to the state!"); Console.WriteLine("Calculating Salary..."); Thread.Sleep(500); leftOver = userSalary - (userSalary * 10 / 100); Console.WriteLine("Your Salary after taxation is: $" + leftOver); } } } https://stackoverflow.com/questions/65589973/c-sharp-value-unitialized January 06, 2021 at 11:54AM
没有评论:
发表评论