Answer the question
In order to leave comments, you need to log in
Calculator log output?
Here's the deal. I store the value of the result of the calculation in stat. sheet, then I try to deduce all values in a certain broad gull. However, only the latter is displayed. Where did I fly?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Collections.Concurrent;
namespace FirstCalc.Controllers
{
public class HomeController : Controller
{
public static List<string> History = new List<string>();
public ActionResult Calc(string arg1, string arg2, string math)
{
decimal a = 0;
decimal b = 0;
string result = "";
if (!decimal.TryParse(arg1, out a) || !decimal.TryParse(arg2, out b))
result = "enter the arguments";
switch (math)
{
case "+":
result = "Result:"+(a + b).ToString();
break;
case "-":
result = "Result:"+(a - b).ToString();
break;
case "*":
result = "Result:"+(a * b).ToString();
break;
case "/":
result = b != 0 ?
(a / b).ToString()
: "error";
break;
default:
result = "enter the arguments";
break;
}
History.Add(result);
foreach (string r in History)
{
result = r;
}
return View(model: result);
}
}
}
@{
ViewBag.Title = "Calc";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<form action="@Url.Action("Calc", "Home")">
arg1</nav><input type="text" id="arg1" name="arg1" /><br /><br />
arg2<input type="text" id="arg2" name="arg2" /><br />
<output>@Model</output><br />
<input type="radio" name="math" value="+" />+<br />
<input type="radio" name="math" value="-" />-<br />
<input type="radio" name="math" value="*" />*<br />
<input type="radio" name="math" value="/" />/<br />
<input type="submit" value="=" />
</form>
Answer the question
In order to leave comments, you need to log in
If you get all the values here
foreach (string r in History)
{
result = r;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question