Please help me understand (c#)
Iâm trying to write some code for a very basic calculator. In my mind, it should work, but I keep getting an error saying Iâm using the âanswerâ variable without assigning it a value. Wouldnât the switch statement do that? I donât get it :/ The code looks like this | | V using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { //creates variables and sets values int num1 = Convert.ToInt32(Console.ReadLine()); string modifier = Console.ReadLine(); int num2 = Convert.ToInt32(Console.ReadLine()); int answer; //sets answer value switch(modifier){ case "+": answer = num1 + num2; break; case "-": answer = num1 - num2; break; case "*": answer = num1 * num2; break; case "/": answer = num1 / num2; break; } Console.WriteLine("{0} {1} {3} = {4}", num1, modifier, num2, answer); } } }