From a0faea8d65e939a7b22e4cc094e9a9facfe4b0b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D1=8F=D0=BD=D0=B0=20=D0=BA=D0=B0=D0=B9=D1=82=D1=83=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0?= Date: Sun, 1 Mar 2026 19:45:30 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=203=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CalculatorController.cs | 28 +++++++++++++++++++ WebApplicationStart/Program.cs | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 WebApplicationStart/Controllers/CalculatorController.cs diff --git a/WebApplicationStart/Controllers/CalculatorController.cs b/WebApplicationStart/Controllers/CalculatorController.cs new file mode 100644 index 0000000..2691682 --- /dev/null +++ b/WebApplicationStart/Controllers/CalculatorController.cs @@ -0,0 +1,28 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebApplicationStart.Controllers +{ + public class CalculatorController : Controller + { + public string Index(double num1, double num2, string operation) + { + switch (operation) + { + case "+": + return $"{num1} + {num2} = {num1 + num2}"; + case "-": + return $"{num1} - {num2} = {num1 - num2}"; + case "*": + return $"{num1} * {num2} = {num1 * num2}"; + case "/": + if (num2 == 0) + { + Console.WriteLine("Ошибка: деление на ноль!"); + } + return $"{num1} / {num2} = {num1 / num2}"; + default: + return "Ошибка: неверный оператор!"; + } + } + } +} diff --git a/WebApplicationStart/Program.cs b/WebApplicationStart/Program.cs index 3155fc3..d1eea4e 100644 --- a/WebApplicationStart/Program.cs +++ b/WebApplicationStart/Program.cs @@ -18,6 +18,6 @@ app.MapControllerRoute( name: "default", - pattern: "{controller=Home}/{action=Index}/{id?}"); + pattern: "{controller=Home}/{action=Index}/{num1?}/{num2?}/{operation?}"); app.Run(); From c2419b7f801d2b7e17d5a89476de19b79c0fe2df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D1=8F=D0=BD=D0=B0=20=D0=BA=D0=B0=D0=B9=D1=82=D1=83=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0?= Date: Mon, 16 Mar 2026 21:57:49 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20=D0=B7=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebApplicationStart/Controllers/CalculatorController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WebApplicationStart/Controllers/CalculatorController.cs b/WebApplicationStart/Controllers/CalculatorController.cs index 2691682..155b22d 100644 --- a/WebApplicationStart/Controllers/CalculatorController.cs +++ b/WebApplicationStart/Controllers/CalculatorController.cs @@ -4,7 +4,7 @@ namespace WebApplicationStart.Controllers { public class CalculatorController : Controller { - public string Index(double num1, double num2, string operation) + public string Index(double num1=0, double num2 = 0, string operation="+") { switch (operation) {