Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace DomashnoOperationBetweenNumbers
- {
- class Program
- {
- static void Main(string[] args)
- {
- // get input --> int n1 and n2; char - +, -, *, /, %;
- // test if n2 == 0; if true print -> "Cannot divide {N1} by zero"
- // calculate result
- // decide if the result is even or odd
- // print --> + - * -> "{N1} {оператор} {N2} = {резултат} – {even/odd}"; / -> "{N1} / {N2} = {резултат}"; % -> "{N1} % {N2} = {остатък}"
- int n1 = int.Parse(Console.ReadLine());
- int n2 = int.Parse(Console.ReadLine());
- string operation = Console.ReadLine();
- if (n2 == 0 && (operation == "/" || operation == "%"))
- {
- Console.WriteLine($"Cannot divide {n1} by zero");
- }
- else
- {
- double result = 0.00;
- string evenOrOdd = "0";
- if (operation == "+")
- {
- result = n1 + n2;
- double evenOrOddcalc = result % 2;
- if (evenOrOddcalc == 0)
- {
- evenOrOdd = "even";
- }
- else
- {
- evenOrOdd = "odd";
- }
- }
- else if (operation == "-")
- {
- result = n1 - n2;
- double evenOrOddcalc = result % 2;
- if (evenOrOddcalc == 0)
- {
- evenOrOdd = "even";
- }
- else
- {
- evenOrOdd = "odd";
- }
- }
- else if (operation == "*")
- {
- result = n1 * n2;
- double evenOrOddcalc = result % 2;
- if (evenOrOddcalc == 0)
- {
- evenOrOdd = "even";
- }
- else
- {
- evenOrOdd = "odd";
- }
- }
- else if (operation == "/")
- {
- result = 1.00 * n1 / n2;
- }
- else
- {
- result = n1 % n2;
- }
- if (operation == "+")
- {
- Console.WriteLine($"{n1} {operation} {n2} = {result} - {evenOrOdd}");
- }
- else if (operation == "-")
- {
- Console.WriteLine($"{n1} {operation} {n2} = {result} - {evenOrOdd}");
- }
- else if (operation == "*")
- {
- Console.WriteLine($"{n1} {operation} {n2} = {result} - {evenOrOdd}");
- }
- else if (operation == "/")
- {
- Console.WriteLine($"{n1} / {n2} = {result:f2}");
- }
- else // operation == "%"
- {
- Console.WriteLine($"{n1} % {n2} = {result}");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment