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 TestCalc.Models
- {
- internal class Calculator
- {
- public float Calculate()
- {
- bool is_running = true;
- Console.WriteLine("Введите первое число:");
- float a = (int)Convert.ToDouble(Console.ReadLine());
- float total = a;
- while (is_running)
- {
- Console.WriteLine("Введите оператор:");
- char opChar = Convert.ToChar(Console.ReadLine());
- if (opChar == '=')
- break;
- Console.WriteLine("Введите второе число:");
- float b = (int) Convert.ToDouble(Console.ReadLine());
- Calculation op;
- switch (opChar)
- {
- case '+':
- op = new Plus();
- break;
- case '-':
- op = new Minus();
- break;
- case '*':
- op = new Multiply();
- break;
- case '/':
- op = new Devide();
- break;
- default: throw new NotSupportedException("Неверная операция!");
- }
- total = op.Calculate(total, b);
- }
- Console.WriteLine("Результат вычисления:");
- return total;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement