anizko

07. Operations Between Numbers

Apr 1st, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Operations_Between_Numbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.  
  10.             double n1 = double.Parse(Console.ReadLine());
  11.             double n2 = double.Parse(Console.ReadLine());
  12.             string operation = Console.ReadLine();
  13.             double total = 0;
  14.             string EvenOdd = string.Empty;
  15.  
  16.             switch (operation)
  17.             {
  18.                 case "+":
  19.                     total = n1 + n2;
  20.                     break;
  21.                 case "-":
  22.                     total = n1 - n2;
  23.                     break;
  24.                 case "*":
  25.                     total = n1 * n2;
  26.                     break;
  27.                 case "/":
  28.                     total = n1 / n2;
  29.                     break;
  30.                 case "%":
  31.                     total = n1 % n2;
  32.                     break;
  33.             }
  34.             if (operation == "+" || operation == "-" || operation == "*")
  35.             {
  36.                 if (total % 2 == 0)
  37.                 {
  38.                     EvenOdd = "even";
  39.                 }
  40.                 else
  41.                 {
  42.                     EvenOdd = "odd";
  43.                 }
  44.                 Console.WriteLine($"{n1} {operation} {n2} = {total} - {EvenOdd}");
  45.             }
  46.             else if (operation == "/")
  47.             {
  48.                 if (n1 != 0)
  49.                 {
  50.                     Console.WriteLine($"{n1} {operation} {n2} = {total:f2}");
  51.                 }
  52.                 else
  53.                 {
  54.                     Console.WriteLine($"Cannot divide {n1} by zero");
  55.                 }
  56.             }
  57.             else if (operation == "%")
  58.                 if (n1 != 0)
  59.                 {
  60.                     Console.WriteLine($"{n1} {operation} {n2} = {total}");
  61.                 }
  62.                 else
  63.                 {
  64.                     Console.WriteLine($"Cannot divide {n1} by zero");
  65.                 }
  66.         }
  67.  
  68.  
  69.     }
  70.  
  71.         }
Advertisement
Add Comment
Please, Sign In to add comment