Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic.CompilerServices;
- using System;
- using System.Linq;
- namespace Phoenix_Calculator
- {
- class Program
- {
- public static void Main(string[] args)
- {
- /*
- * Console.WriteLine("Одно число");
- * Console.WriteLine("Два числа");
- * Console.WriteLine("Теорема пифагора");
- * Console.WriteLine("Дискриминант");
- */
- bool exit = false;
- do
- {
- Console.WriteLine("Операции с:" + Environment.NewLine +
- "1. Одним числом" + Environment.NewLine +
- "2. Двумя числами" + Environment.NewLine +
- "3. Теорема пифагора" + Environment.NewLine +
- "4. Решение квадратных уравнений" + Environment.NewLine +
- "5. Выйти из приложения");
- string operationIndex = Console.ReadLine();
- switch (operationIndex)
- {
- case "1":
- Console.Write("Введите число: ");
- try
- {
- int x = int.Parse(Console.ReadLine());
- for (int i = 1; i < 10; i++)
- {
- Console.WriteLine(string.Format("Степень {0} числа {1} - {2}", i, x, RaiseToPower(x, i)));
- }
- Console.WriteLine(Environment.NewLine + string.Format("Корень числа {0} - {1}", x, Math.Sqrt(x)));
- } catch (FormatException e)
- {
- ErrorMessage(e.Message);
- }
- break;
- case "2":
- bool secondPass = false;
- do
- {
- Console.WriteLine("Введите выражение в формате: x (операция) y" + Environment.NewLine +
- "Выражения: +, -, *, /, >, <, =, >=, <=");
- Console.Write("Ввод: ");
- string sentence = Console.ReadLine();
- string[] subSentece = sentence.Split(' ');
- try
- {
- if (subSentece.Length == 3)
- {
- double x = double.Parse(subSentece[0]);
- double y = double.Parse(subSentece[2]);
- switch (subSentece[1])
- {
- case "+":
- Console.WriteLine(string.Format("{0} = {1}", sentence, x + y));
- secondPass = true;
- break;
- case "-":
- Console.WriteLine(string.Format("{0} = {1}", sentence, x - y));
- secondPass = true;
- break;
- case "*":
- Console.WriteLine(string.Format("{0} = {1}", sentence, x * y));
- secondPass = true;
- break;
- case "/":
- Console.WriteLine(string.Format("{0} = {1}", sentence, x / y));
- secondPass = true;
- break;
- case ">":
- Console.WriteLine(string.Format("{0}? {1}", sentence, x > y));
- secondPass = true;
- break;
- case "<":
- Console.WriteLine(string.Format("{0}? {1}", sentence, x < y));
- secondPass = true;
- break;
- case "=":
- Console.WriteLine(string.Format("{0}? {1}", sentence, x == y));
- secondPass = true;
- break;
- case ">=":
- Console.WriteLine(string.Format("{0}? {1}", sentence, x >= y));
- secondPass = true;
- break;
- case "<=":
- Console.WriteLine(string.Format("{0}? {1}", sentence, x <= y));
- secondPass = true;
- break;
- default:
- ErrorMessage("не допустимая операция");
- break;
- }
- }
- else
- {
- ErrorMessage("не верный формат");
- }
- } catch (FormatException e)
- {
- ErrorMessage(e.Message);
- }
- } while (!secondPass);
- break;
- case "3":
- bool thirdPass = false;
- do
- {
- try
- {
- Console.Write("Введите два катета" + Environment.NewLine +
- "AB: ");
- double a = double.Parse(Console.ReadLine());
- Console.Write("BC: ");
- double b = double.Parse(Console.ReadLine());
- Console.WriteLine(string.Format("Гипотенуза AC = {0}", Math.Sqrt(a*a + b*b)));
- thirdPass = true;
- }
- catch (FormatException e)
- {
- ErrorMessage(e.Message);
- }
- } while (!thirdPass);
- break;
- case "4":
- bool fourthPass = false;
- do
- {
- try
- {
- Console.Write("Введите три аргумента" + Environment.NewLine +
- "A: ");
- double a = double.Parse(Console.ReadLine());
- Console.Write("B: ");
- double b = double.Parse(Console.ReadLine());
- Console.Write("C: ");
- double c = double.Parse(Console.ReadLine());
- if (a == 0 || b == 0 || c == 0)
- {
- FormatException formatException = new FormatException("у тебя один из операторов нулевой");
- throw formatException;
- }
- double D = b * b - 4 * a * c;
- double x1 = (-b + Math.Sqrt(D)) / (2 * a);
- double x2 = (-b - Math.Sqrt(D)) / (2 * a);
- if (D < 0)
- {
- Console.WriteLine("Дискриминант = " + D);
- Console.WriteLine("У уравнения нет корней");
- }
- else
- {
- Console.WriteLine(string.Format("Дискриминант: {0}{1}X1 = {2}; X2 = {3}", D, Environment.NewLine, x1, x2));
- }
- fourthPass = true;
- }
- catch (FormatException e)
- {
- ErrorMessage(e.Message);
- }
- } while (!fourthPass);
- break;
- case "5":
- exit = true;
- break;
- default:
- ErrorMessage("число не от одного до четырех");
- break;
- }
- } while (!exit);
- }
- private static void ErrorMessage(string message)
- {
- Console.WriteLine(string.Format("Ты ебаный мудак, {0}", message));
- }
- private static double RaiseToPower(double x, double y)
- {
- double result = x;
- for (int i = 1; i < y; i++)
- {
- result *= x;
- }
- return result;
- }
- }
- }
Add Comment
Please, Sign In to add comment