Advertisement
vanina

operation C# basic

Jun 23rd, 2017
98
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 exam_24_04
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var a = double.Parse(Console.ReadLine());
  14. var b = double.Parse(Console.ReadLine());
  15. var operation = Console.ReadLine();
  16.  
  17. switch (operation)
  18. {
  19. case "+":
  20. Console.WriteLine("{0} {1} {2} = {3} - {4}", a, operation, b, a + b, (a + b) % 2 == 0 ? "even" : "odd"); break;
  21. case "-":
  22. Console.WriteLine("{0} {1} {2} = {3} - {4}", a, operation, b, (a - b), (a - b) % 2 == 0 ? "even" : "odd"); break;
  23. case "*":
  24. Console.WriteLine("{0} {1} {2} = {3} - {4}", a, operation, b, a * b, (a * b) % 2 == 0 ? "even" : "odd"); break;
  25. case "/":
  26. if (b == 0)
  27. {
  28. Console.WriteLine("Cannot divide {0} by zero", a);break;
  29. }
  30. else
  31. {
  32. Console.WriteLine("{0} {1} {2} = {3:f2}", a, operation, b, a / b); break;
  33. }
  34. case "%":
  35.  
  36. if (b == 0)
  37. {
  38. Console.WriteLine("Cannot divide {0} by zero", a); break;
  39. }
  40. else
  41. {
  42. Console.WriteLine("{0} {1} {2} = {3}", a, operation, b, a % b); break;
  43. }
  44. }
  45. }
  46.  
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement