Advertisement
NonaG

Operations

Dec 14th, 2016
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 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. var n1 = int.Parse(Console.ReadLine());
  14. var n2 = int.Parse(Console.ReadLine());
  15. var oper = Console.ReadLine();
  16. double result = 0.00;
  17. if (n2 != 0 && (oper == "+" || oper == "-" || oper == "*"))
  18. {
  19. if (oper == "+")
  20. {
  21. result = n1 + n2;
  22. }
  23. else if (oper == "-")
  24. {
  25. result = n1 - n2;
  26. }
  27. else if (oper == "*")
  28. {
  29. result = n1 * n2;
  30. }
  31.  
  32. if (result % 2 == 0)
  33. {
  34. Console.WriteLine("{0} {1} {2} = {3} - even", n1, oper, n2, result);
  35. }
  36. else
  37. {
  38. Console.WriteLine("{0} {1} {2} = {3} - odd", n1, oper, n2, result);
  39. }
  40. }
  41. else if (n2 == 0 && (oper == "/" || oper == "%"))
  42. {
  43. Console.WriteLine("Cannot divide {0} by zero", n1);
  44. }
  45. else if (n2 != 0 && (oper == "/" || oper == "%"))
  46. {
  47. if (oper == "/")
  48. {
  49. result = (double)n1 / n2;
  50. Console.WriteLine("{0} {1} {2} = {3}", n1, oper, n2,Math.Round(result,2));
  51. }
  52. else if (oper == "%")
  53. {
  54. result = n1 % n2;
  55. Console.WriteLine("{0} {1} {2} = {3}", n1, oper, n2, result);
  56. }
  57.  
  58. }
  59.  
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement