我想初始化3種不同的方法並獲取錯誤。爲什麼我得到這個錯誤試圖創建這些方法?
這個變量不會在目前情況下
我想它,因爲範圍存在,但我不知道怎樣才能改變calculatebmi()
或calculateextime()
方法不搞亂起來。
我該如何擺脫這個錯誤?它抱怨oldbmi
,time
和newbmi
。
相關代碼:
public partial class Program2 : Form
{
private double _height;
private double _weight;
const int caloriesBurned = 10000;
const int walkingSpeed = 4;
const double fatCaloriesPerPound = 3500;
const double metricWalkingSpeed = walkingSpeed/.62137;
private double calculateBmi(double metricWeight, double metricHeight)
{
double oldBmi = metricWeight/Math.Pow(metricHeight, 2);
double newMetricWeight = metricWeight - (caloriesBurned/(fatCaloriesPerPound * 2.2046));
double newBmi = newMetricWeight/Math.Pow(metricHeight, 2);
return oldBmi;
}
private double calculateExTime(double metricWeight, double metricHeight)
{
double exerciseMultiplier = .0215 * Math.Pow(metricWalkingSpeed, 3)
- .1765 * Math.Pow(metricWalkingSpeed, 2)
+ .8710 * metricWalkingSpeed
+ 1.4577;
double time = caloriesBurned/(exerciseMultiplier * metricWeight);
return time;
}
private void displayresults(double _height, double _weight, double oldbmi,double time, double newBmi)
{
double newWeight = _weight - (caloriesBurned/fatCaloriesPerPound);
int feet = (int)_height/12;
int inches = (int)_height % 12;
HeightText.Text = string.Format("{0}ft {1}in", feet, inches);
Weight.Text = _weight.ToString();
OriginalBmi.Text = oldBmi.ToString("F2");
NewBmi.Text = newBmi.ToString("F2");
NewWeight.Text = newWeight.ToString("F2");
ExerciseTime.Text = string.Format("{0} hrs {1} min", (int)(time), (int)(time % 60));
}
displayresults(_height, _weight,oldBmi,time,newBmi);
*哪個*變量是抱怨,哪裏*?您目前已發佈超過120行代碼 - 請將其縮減爲一個簡短但完整的程序,以展示問題。 – 2014-10-27 17:49:29
現在你已經刪除了*這麼多*,沒有跡象表明你在班上有什麼變數。我要求一個簡短的*但完整的*程序。 *您是否在聲明編譯器抱怨的變量?如果是這樣,在哪裏? – 2014-10-27 17:55:38
那麼你在哪裏調用'displayresults'方法? – Shaharyar 2014-10-27 17:59:46