Advertisement
tsvetelinapasheva

TsvetelinaPasheva/ConditionalStatementsAdvancedExercise/06.OperationsBetweenNumbers

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