Advertisement
zarkoboyadjiev

Operation Between Numbers

Oct 31st, 2018
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 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 numberOperations
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double n1 = double.Parse(Console.ReadLine());
  14.             double n2 = double.Parse(Console.ReadLine());
  15.             string operation = Console.ReadLine();
  16.             double result = 0;
  17.             string odd;
  18.             if (n2 == 0 && (operation == "/" || operation == "%"))
  19.             {
  20.  
  21.                 Console.WriteLine("Cannot divide {0} by zero",n1);
  22.             }
  23.             else
  24.             {
  25.                 switch (operation)
  26.                 {
  27.                     case "+":
  28.                         result = n1 + n2;
  29.                         if (result % 2 == 0)
  30.                         {
  31.                             odd = "even";
  32.                         }
  33.                         else
  34.                         {
  35.                             odd = "odd";
  36.                         }
  37.                         Console.WriteLine($"{n1} + {n2} = {result} - {odd}");
  38.                         break;
  39.  
  40.                     case "-":
  41.                         result = n1 - n2;
  42.                         if (result % 2 == 0)
  43.                         {
  44.                             odd = "even";
  45.                         }
  46.                         else
  47.                         {
  48.                             odd = "odd";
  49.                         }
  50.                         Console.WriteLine($"{n1} - {n2} = {result} - {odd}");
  51.                         break;
  52.  
  53.                     case "*":
  54.                         result = n1 * n2;
  55.                         if (result % 2 == 0)
  56.                         {
  57.                             odd = "even";
  58.                         }
  59.                         else
  60.                         {
  61.                             odd = "odd";
  62.                         }
  63.                         Console.WriteLine($"{n1} * {n2} = {result} - {odd}");
  64.                         break;
  65.  
  66.                     case "/":
  67.                         result = n1 / n2;
  68.                         Console.WriteLine($"{n1} / {n2} = {result:F2}");
  69.                         break;
  70.  
  71.                     case "%":
  72.                         result = n1 % n2;
  73.                         Console.WriteLine($"{n1} % {n2} = {result}");
  74.                         break;
  75.  
  76.                     default:
  77.                         break;
  78.                 }
  79.             }            
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement