Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions WebApplicationStart/Controllers/CalculatorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;

namespace WebApplicationStart.Controllers
{
public class CalculatorController : Controller
{
public string Index(double num1=0, double num2 = 0, 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("Ошибка: деление на ноль!");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

куда?!!!!

}
return $"{num1} / {num2} = {num1 / num2}";
default:
return "Ошибка: неверный оператор!";
}
}
}
}
2 changes: 1 addition & 1 deletion WebApplicationStart/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
pattern: "{controller=Home}/{action=Index}/{num1?}/{num2?}/{operation?}");

app.Run();