Advertisement
LardaX

Operations Problem?

Jul 6th, 2016
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 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 Operations
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int numberOne = int.Parse(Console.ReadLine());
  14.             int numberTwo = int.Parse(Console.ReadLine());
  15.             string operation = Console.ReadLine();
  16.             int result = 0;
  17.             string evenOrOdd = null;
  18.  
  19.             if (operation == "+" || operation == "-" || operation == "*")
  20.             {
  21.                 if (operation == "+")
  22.                 {
  23.                     result = numberOne + numberTwo;
  24.                 }
  25.                 else if (operation == "-")
  26.                 {
  27.                     result = numberOne - numberTwo;
  28.                 }
  29.                 else if (operation == "*")
  30.                 {
  31.                     result = numberOne * numberTwo;
  32.                 }
  33.  
  34.                 if (result % 2 == 0)
  35.                 {
  36.                     evenOrOdd = "even";
  37.                 }
  38.                 else
  39.                 {
  40.                     evenOrOdd = "odd";
  41.                 }
  42.  
  43.                 Console.WriteLine("{0} {1} {2} = {3} - {4}", numberOne, operation, numberTwo, result, evenOrOdd);
  44.             }
  45.  
  46.             if (operation == "/" || operation == "%")
  47.             {
  48.                 if (numberTwo == 0)
  49.                 {
  50.                     Console.WriteLine($"Cannot divide {numberOne} by zero");
  51.                 }
  52.                 else if (operation == "/")
  53.                 {
  54.                     Console.WriteLine($"{numberOne} / {numberTwo} = {(double) numberOne / numberTwo}");
  55.                 }
  56.                 else if (operation == "%")
  57.                 {
  58.                     Console.WriteLine($"{numberOne} % {numberTwo} = {numberOne % numberTwo}");
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement