Orange North

Orange North

  • NA
  • 2
  • 963

I need help with my simple calculator!

Apr 21 2017 10:13 AM
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'


  1. class Program  
  2.     {  
  3.         static void Main(string[] args)  
  4.         {  
  5.   
  6.               
  7.   
  8.               
  9.             int num01 = Convert.ToInt32(Console.Read());  
  10.             char method = Console.ReadKey().KeyChar;  
  11.             int num02 = Convert.ToInt32(Console.Read());  
  12.             int result;  
  13.   
  14.   
  15.             switch (method)  
  16.             {  
  17.                 case '+':  
  18.                     result = num01 + num02;  
  19.                     break;  
  20.                 case '-':  
  21.                     result = num01 - num02;  
  22.                     break;  
  23.                 case '%':  
  24.                     result = num01 % num02;  
  25.                     break;  
  26.                 case '*':  
  27.                     result = num01 * num02;  
  28.                     break;  
  29.                 default:  
  30.                     Console.WriteLine("???");  
  31.                     break;  
  32.             }  
  33.   
  34.             Console.WriteLine("The answer is " , result);  
  35.   
  36.             Console.ReadKey();  
  37.  
  38.           
  39.         }  
  40.   
  41.   
  42.     }
  43.  

Answers (3)