Advertisement
kzborisov

Operations

Sep 22nd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 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 Operations
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. decimal n1 = decimal.Parse(Console.ReadLine());
  14. decimal n2 = decimal.Parse(Console.ReadLine());
  15. string nOperator = Console.ReadLine();
  16.  
  17. decimal result = 0.00M;
  18. string output = string.Empty;
  19.  
  20. if (n2 == 0 && (nOperator.Equals("/") || nOperator.Equals("%")))
  21. {
  22. output = string.Format("Cannot divide {0} by zero", n1);
  23. }
  24. else if (nOperator.Equals("/"))
  25. {
  26. result = n1 / n2;
  27. output = string.Format("{0} {1} {2} = {3:F2}",
  28. n1, nOperator, n2, result);
  29. }
  30. else if (nOperator.Equals("%"))
  31. {
  32. result = n1 % n2;
  33. output = string.Format("{0} {1} {2} = {3}",
  34. n1, nOperator, n2, result);
  35. }
  36. else
  37. {
  38. if (nOperator.Equals("+"))
  39. {
  40. result = n1 + n2;
  41. }
  42. else if (nOperator.Equals("-"))
  43. {
  44. result = n1 - n2;
  45. }
  46. else if (nOperator.Equals("*"))
  47. {
  48. result = n1 * n2;
  49. }
  50.  
  51. output = string.Format("{0} {1} {2} = {3} - {4}",
  52. n1, nOperator, n2, result,
  53. result % 2 == 0 ? "even" : "odd");
  54. }
  55.  
  56. Console.WriteLine(output);
  57. }
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement