fork download
  1. // Implementing a calculator in
  2. // C# using switch statement.
  3. using System;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace calculator_c_sharp
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string value;
  14. do
  15. {
  16. int res;
  17. Console.Write("Enter first number:");
  18. int num1 = Convert.ToInt32(Console.ReadLine());
  19. Console.Write("Enter second number:");
  20. int num2 = Convert.ToInt32(Console.ReadLine());
  21. Console.Write("Enter symbol(/,+,-,*):");
  22. string symbol = Console.ReadLine();
  23.  
  24. switch (symbol)
  25. {
  26. case "+":
  27. res = num1 + num2;
  28. Console.WriteLine("Addition:" + res);
  29. break;
  30. case "-":
  31. res = num1 - num2;
  32. Console.WriteLine("Subtraction:" + res);
  33. break;
  34. case "*":
  35. res = num1 * num2;
  36. Console.WriteLine("Multiplication:" + res);
  37. break;
  38. case "/":
  39. res = num1 / num2;
  40. Console.WriteLine("Division:" + res);
  41. break;
  42. default:
  43. Console.WriteLine("Wrong input");
  44. break;
  45. }
  46. Console.ReadLine();
  47. Console.Write("Do you want to continue(y/n):");
  48. value = Console.ReadLine();
  49. }
  50. while (value=="y" || value=="Y");
  51. }
  52. }
  53.  
  54. }
  55.  
Success #stdin #stdout 0.05s 28636KB
stdin
Standard input is empty
stdout
Enter first number:Enter second number:Enter symbol(/,+,-,*):Wrong input
Do you want to continue(y/n):