Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp5
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. double n1 = double.Parse(Console.ReadLine());
  10. double n2 = double.Parse(Console.ReadLine());
  11. char function = char.Parse(Console.ReadLine());
  12. double result = 0.0;
  13. string evenOdd = "neutral";
  14.  
  15. if (function != '/')
  16. {
  17.  
  18.  
  19. if (function == '+')
  20. {
  21. result = n1 + n2;
  22.  
  23. }
  24. else if (function == '-')
  25. {
  26. result = n1 - n2;
  27. }
  28. else if (function == '*')
  29. {
  30. result = n1 * n2;
  31. }
  32. else if (function == '%')
  33. {
  34. result = n1 % n2;
  35. }
  36. if (result % 2 == 0)
  37. {
  38. evenOdd = "even";
  39. }
  40. else
  41. {
  42. evenOdd = "odd";
  43. }
  44. Console.WriteLine($"{n1} {function} {n2} = {result} - {evenOdd}");
  45. }
  46.  
  47.  
  48.  
  49. else if (function == '/' && n2!=0)
  50. {
  51. result = n1 / n2;
  52. Console.WriteLine($"{n1} {function} {n2} = {result:F2}");
  53. }
  54.  
  55. else if (n2 == 0 && function == '/')
  56. {
  57. Console.WriteLine($"Cannot divide {n1} by zero");
  58. }
  59.  
  60.  
  61.  
  62. }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement