Advertisement
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 CalCulator
- {
- class Program
- {
- public double calculate(double x1, double x2, string operation)
- {
- double result = 0;
- switch(operation)
- {
- case "-":
- result = x1 - x2;
- break;
- case "+":
- result = x1 + x2;
- break;
- case "*":
- result = x1* x2;
- break;
- case "/":
- if(x2 == 0)
- {
- Console.WriteLine("ты неверный!!!!!");
- break;
- }
- result = x1 / x2;
- break;
- case "%":
- result = x1 % x2;
- break;
- }
- return result;
- }
- static void Main(string[] args)
- {
- Console.WriteLine("let's start");
- string expression = Console.ReadLine();
- string[] split = expression.Split(new char[] { '+', '-', '/', '*', '%' });
- int operationIndex = Convert.ToInt32(split[0].Length);
- double x1 = Convert.ToDouble(split[0]);
- double x2 = Convert.ToDouble(split[1]);
- String operation1 = expression.Substring(operationIndex, 1);
- double result = calculate(x1, x2, operation1);
- Console.WriteLine(result);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement