IvetValcheva

06. Operations Between

Nov 15th, 2021
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp2
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int num1 = int.Parse(Console.ReadLine());
  10.             int num2 = int.Parse(Console.ReadLine());
  11.             char operation = char.Parse(Console.ReadLine());
  12.  
  13.             double result = 0.0;
  14.  
  15.             if (operation == '+' || operation == '-' || operation == '*')
  16.             {
  17.                 string evenOrOdd = "odd";
  18.  
  19.                 if (operation == '+')
  20.                 {
  21.                     result = num1 + num2;
  22.                 }
  23.                 else if (operation == '-')
  24.                 {
  25.                     result = num1 - num2;
  26.                 }
  27.                 else if (operation == '*')
  28.                 {
  29.                     result = num1 * num2;
  30.                 }
  31.  
  32.                 if (result % 2 == 0)
  33.                 {
  34.                     evenOrOdd = "even";
  35.                 }
  36.  
  37.                 Console.WriteLine($"{num1} {operation} {num2} = {result} - {evenOrOdd}");
  38.             }
  39.             else if (num2 == 0)
  40.             {
  41.                 Console.WriteLine($"Cannot divide {num1} by zero");
  42.             }
  43.             else if(operation == '/')
  44.             {
  45.                 // / -> "{N1} / {N2} = {резултат:F2}"
  46.                 result = 1.0*num1 / num2;
  47.                 Console.WriteLine($"{num1} / { num2} = {result:F2}");
  48.             }
  49.             else
  50.             {
  51.                 result = num1 % num2;
  52.                 // % -> "{N1} % {N2} = {остатък}"
  53.                 Console.WriteLine($"{num1} % {num2} = {result}");
  54.             }
  55.         }
  56.     }
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment