diff --git a/Homework05/Homework05.sln b/Homework05/Homework05.sln new file mode 100644 index 0000000..01df8ad --- /dev/null +++ b/Homework05/Homework05.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Homework05", "Homework05\Homework05.csproj", "{4CB9E2B0-4B50-4947-85FC-2E00393DA325}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4CB9E2B0-4B50-4947-85FC-2E00393DA325}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B7C80557-3166-4939-A5C0-521CB9130E95} + EndGlobalSection +EndGlobal diff --git a/Homework05/Homework05/CannotEnterAnotherSymbolException.cs b/Homework05/Homework05/CannotEnterAnotherSymbolException.cs new file mode 100644 index 0000000..6d7c0d0 --- /dev/null +++ b/Homework05/Homework05/CannotEnterAnotherSymbolException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Homework05 +{ + internal class CannotEnterAnotherSymbolException : Exception + { + public CannotEnterAnotherSymbolException(string str) + : base (str) + { + + } + } +} diff --git a/Homework05/Homework05/Homework05.csproj b/Homework05/Homework05/Homework05.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/Homework05/Homework05/Homework05.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Homework05/Homework05/Program.cs b/Homework05/Homework05/Program.cs new file mode 100644 index 0000000..af116e2 --- /dev/null +++ b/Homework05/Homework05/Program.cs @@ -0,0 +1,59 @@ +namespace Homework05 +{ + internal class Program + { + static void Main(string[] args) + { + try + { + Console.WriteLine("Shell we start calculating!"); + Console.Write("Enter first number : "); + int firstNumber = int.Parse(Console.ReadLine()); + Console.Write("Enter action :"); + char action = Console.ReadLine()[0]; + Console.Write("Enter second number : "); + int secondNumber = int.Parse(Console.ReadLine()); + + Calculate(firstNumber, secondNumber, action); + + } + catch (CannotEnterAnotherSymbolException ex) + { + Console.WriteLine("Wrong symbol . Please, try again"); + } + catch (Exception ex) + { + Console.WriteLine("Something went wrong!"); + } + Thread.Sleep(3000); + Console.Clear(); + Main(args); + } + + public static void Calculate(int firstNum, int secondNum, char action) + { + int result; + + switch (action) + { + case '+': + result = firstNum + secondNum; + break; + case '-': + result = firstNum - secondNum; + break; + case '*': + result = firstNum * secondNum; + break; + case '/': + result = firstNum / secondNum; + break; + default: throw new CannotEnterAnotherSymbolException("Wrong symbol!"); + } + Console.Clear(); + Console.WriteLine($"{firstNum} {action} {secondNum} = {result}"); + + } + + } +} \ No newline at end of file diff --git a/Homework05/Homework05/errors.txt b/Homework05/Homework05/errors.txt new file mode 100644 index 0000000..cd876a9 --- /dev/null +++ b/Homework05/Homework05/errors.txt @@ -0,0 +1 @@ +Value does not fall within the expected range. \ No newline at end of file