PDA

View Full Version : سوال: ایجاد یک صفحه برای محاسبه ی BMI



smrr82
دوشنبه 01 آذر 1395, 22:21 عصر
سلام چه کدی باید برای این بنویسم و تو View چی بنویسم؟
فرمول Bmi : وزن تقسیم بر قد(متر) به توان 2
لطفا سریع بگید:متفکر:



public ActionResult Index()
{
double Weight = new double();
Weight.ToString();
double Height = new double();
Height.ToString();
double BMI = Weight / (Height * Height);

if (BMI <18.5)
{
return Content(" you are thin");
}
if (BMI > 25)
{
return Content ("You Have ezafe vazn and your BMI is : "
}
else
{
return Content("You are good");
}
}

Moien Tajik
سه شنبه 02 آذر 1395, 00:27 صبح
یکم خودتون تلاش کنید ، جایی از برنامتون اگر مشکل داشتید بپرسید نه اینطور که کامل بخواید ...

کامل BMI رو نمیدونم به چه صورت هست ، خودتون عدد حاصل رو میتونید با if چک کنید و جواب رو بر اساس حاصلش تغییر بدین .

ویو :

<h4>@ViewBag.BMI</h4>


@using(Html.BeginForm("BMI", "Home", FormMethod.Post))
{
<span>Weight : </span><input type="text" name="weight"></br>
<span>Height : </span><input type="text" name="height"></br>
<input type="submit" class="btn btn-primary" value="Calculate BMI">
}


اکشن :

[HttpGet]
public ActionResult BMI()
{
return View();
}


[HttpPost]
public ActionResult BMI(int weight , int height)
{
if (!string.IsNullOrEmpty(weight) && !string.IsNullOrEmpty(height))
{
ViewBag.BMI = Math.Pow(2,(weight / height));
}

return View();
}