I am trying to do make a basic program in C# that calculates netPay and grossPay, however I am running into a little problem. I included a switch to set my taxRate to a const based off of a letter provided, after I added the switch into my program it says taxRate is an unassigned local variable. I am still very new to C# so I probably made a very simple mistake but for the life of me I cant find it. thanks in advance for the help.
const int married = 15, single = 22, divorced = 23, widowed = 13;
double payRate, hoursWorked, grossPay, netPay;
double taxRate;
char marStatus;
Console.WriteLine("Please Enter Hourly Wages");
payRate = int.Parse(Console.ReadLine());
Console.WriteLine("Please Enter Hours Worked");
hoursWorked = int.Parse(Console.ReadLine());
Console.WriteLine("Please Enter Marital Status Letter: (M) Married (S) Single (D) Divorced (W) Widowed");
marStatus =Convert.ToChar(Console.ReadLine());
switch (marStatus)
{
case 'M':
taxRate = married;
break;
case 'S':
taxRate = single;
break;
case 'D':
taxRate = divorced;
break;
case 'W':
taxRate = widowed;
break;
default:
Console.WriteLine("Invalid Input, Please Try Again.");
break;
}
if (hoursWorked > 40)
{grossPay =((hoursWorked-40)*(payRate*1.5))+(40*payRate);}
else
{ grossPay = payRate * hoursWorked; }
netPay = grossPay * taxRate; // This is where I have the problem
Console.WriteLine("Gross Pay=" +grossPay);
Console.WriteLine("Net Pay=" +netPay);
Console.WriteLine("xxx");
Console.ReadLine();