I just started learning C# and i wanted to build a simple calculator but I keep getting error messages
The error message I keep getting is :
Error CS0165 Use of unassigned local variable 'result'
Error CS0165 Use of unassigned local variable 'result'
- class Program
- {
- static void Main(string[] args)
- {
- int num01 = Convert.ToInt32(Console.Read());
- char method = Console.ReadKey().KeyChar;
- int num02 = Convert.ToInt32(Console.Read());
- int result;
- switch (method)
- {
- case '+':
- result = num01 + num02;
- break;
- case '-':
- result = num01 - num02;
- break;
- case '%':
- result = num01 % num02;
- break;
- case '*':
- result = num01 * num02;
- break;
- default:
- Console.WriteLine("???");
- break;
- }
- Console.WriteLine("The answer is " , result);
- Console.ReadKey();
-
- }
- }
-

Amit GuptaRank #190 · 12.8K reputationPosted Apr 21, 2017, 6:23 AM EDT
Purushottam PrabhakarRank #3,552 · 410 reputationPosted Apr 22, 2017, 7:48 AM EDT
Karthi KeyanRank #1,926 · 762 reputationPosted Apr 23, 2017, 9:10 PM EDT