Advertisement
Galin_P87

Operations1

Jun 3rd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 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 _17.Operations
  8. {
  9.     class Operations
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double n1 = double.Parse(Console.ReadLine());
  14.             double n2 = double.Parse(Console.ReadLine());
  15.             char operation = char.Parse(Console.ReadLine());
  16.             double result = 0.0;
  17.  
  18.             if (n2 == 0 && (operation == '/' || operation == '%'))
  19.             {
  20.                 Console.WriteLine($"Cannot divide {n1} by zero");
  21.             }
  22.             else if (operation == '/')
  23.             {
  24.                 result = n1 / n2;
  25.                 Console.WriteLine($"{n1} / {n2} = {result:f2}");
  26.             }
  27.             else if (operation == '%')
  28.             {
  29.                 result = n1 % n2;
  30.                 Console.WriteLine($"{n1} % {n2} = {result}");
  31.             }
  32.             else
  33.             {
  34.                 string residue = "even";
  35.                 switch (operation)
  36.                 {
  37.                     case '+':
  38.                         result = n1 + n2;
  39.                         break;
  40.                     case '-':
  41.                         result = n1 - n2;
  42.                         break;
  43.                     default:
  44.                         result = n1 * n2;
  45.                         break;
  46.                 }
  47.                 if (result % 2 == 1)
  48.                 {
  49.                     residue = "odd";
  50.                 }
  51.                 Console.WriteLine($"{n1} {operation} {n2} = {result} - {residue}");
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement