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 ConsoleCalculator
- {
- class Program
- {
- static void Main(string[] args)
- {
- Calc calc = new Calc();
- calc.ShowInstruction();
- do
- {
- try
- {
- calc.GetChoise();
- calc.Calculate();
- }
- catch
- {
- Console.WriteLine("Некорректный ввод");
- }
- }
- while (calc.UserChoise != 'q');
- }
- }
- class Calc
- {
- private double first, second;
- private char usrChoise;
- public char UserChoise
- {
- get
- {
- return usrChoise;
- }
- }
- public void ShowInstruction()
- {
- Console.WriteLine("Введите требуемую операцию одиночным симовлом");
- Console.WriteLine("'+' - Сложение");
- Console.WriteLine("'-' - Вычитание");
- Console.WriteLine("'*' - Умножение");
- Console.WriteLine("'/' - Деление");
- Console.WriteLine("'^' - Возведение в степень");
- Console.WriteLine("'q' - Выход из программы" + Environment.NewLine);
- }
- public void GetChoise()
- {
- Console.Write("Введите первое число: ");
- first = Int32.Parse(Console.ReadLine());
- Console.Write("Введите второе число: ");
- second = Int32.Parse(Console.ReadLine());
- Console.Write("Введите требуемую операцию: ");
- usrChoise = Char.Parse(Console.ReadLine());
- }
- public void Calculate()
- {
- switch (usrChoise)
- {
- case '+': Console.WriteLine("{0} + {1} = {2}", first, second, (first + second));
- break;
- case '-': Console.WriteLine("{0} - {1} = {2}", first, second, (first - second));
- break;
- case '*': Console.WriteLine("{0} * {1} = {2}", first, second, (first * second));
- break;
- case '/': Console.WriteLine("{0} / {1} = {2}", first, second, (first / second));
- break;
- case '^': Console.WriteLine("{0} ^ {1} = {2}", first, second, (Math.Pow(first, second)));
- break;
- default:
- if (usrChoise != 'q')
- ShowInstruction();
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement