Advertisement
Tesla4you

Untitled

Feb 20th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CalCulator
  8. {
  9. class Program
  10. {
  11. public double calculate(double x1, double x2, string operation)
  12. {
  13. double result = 0;
  14. switch(operation)
  15. {
  16. case "-":
  17. result = x1 - x2;
  18. break;
  19. case "+":
  20. result = x1 + x2;
  21. break;
  22. case "*":
  23. result = x1* x2;
  24. break;
  25. case "/":
  26. if(x2 == 0)
  27. {
  28. Console.WriteLine("ты неверный!!!!!");
  29. break;
  30. }
  31. result = x1 / x2;
  32. break;
  33. case "%":
  34. result = x1 % x2;
  35. break;
  36. }
  37. return result;
  38. }
  39.  
  40.  
  41. static void Main(string[] args)
  42. {
  43. Console.WriteLine("let's start");
  44. string expression = Console.ReadLine();
  45.  
  46. string[] split = expression.Split(new char[] { '+', '-', '/', '*', '%' });
  47.  
  48. int operationIndex = Convert.ToInt32(split[0].Length);
  49. double x1 = Convert.ToDouble(split[0]);
  50. double x2 = Convert.ToDouble(split[1]);
  51. String operation1 = expression.Substring(operationIndex, 1);
  52.  
  53. double result = calculate(x1, x2, operation1);
  54.  
  55.  
  56. Console.WriteLine(result);
  57.  
  58. Console.ReadKey();
  59.  
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement