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
22 changes: 22 additions & 0 deletions WebApplicationLesson1/Controllers/CalculatorController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc;

namespace WebApplicationLesson1.Controllers
{
public class CalculatorController : Controller
{
public string Index(double a, double b, char c)
{
if (c == '*')
return $"{a} {c} {b} = {a * b}";
if (c == '-')
return $"{a} {c} {b} = {a - b}";
if (c == '/' && b != 0)
return $"{a} {c} {b} = {a / b}";
if (c == '/' && b == 0)
return "Ошибка: деление на ноль.";
if (c != '+' && c != 0)
return "Некорректная операция.";
return $"{a} + {b} = {a + b}";
}
}
}
2 changes: 1 addition & 1 deletion WebApplicationLesson1/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
pattern: "{controller=Home}/{action=Index}/");
});
}
}
Expand Down