c# - Why am I getting this error trying to create these methods? -


After

I am trying to get started in 3 different ways and getting the error.

This variable does not exist in the current context

I'm thinking of scope because of this but I do not think how I Calculatebmi () or after computing () the methods are unmistakable to them

How can I get rid of this error? It has complained about oldbmi , time , and newbmi

related code:.

  Public Partial Class Program 2: Form {Personal Double _height; Private double _ weight; Const int caloriesBurned = 10000; Constant int running speed = 4; Constant double weightcaleries peerpand = 3500; Const twice double matriculation speed = wining speed / .62137; Private double calculation BBI (Double Metric Wight, Double Metric Hight) {Double Old Beamy = Metric Wight / Math Po (metrichyte, 2); Double New Metric Wight = Metric Wight - (Calorie Burn / / (Fat CliplerPand * 2.2046); Double Newbie = New Metric Wight / Math Po (metrichyte, 2); Return old; } Private double calculateExTime (double metricWeight, double metricHeight) {double exerciseMultiplier = 0.0215 * Math.Pow (metricWalkingSpeed, 3) - 0.1765 * Math.Pow (metricWalkingSpeed, 2) + 0.8710 * metricWalkingSpeed ​​+ 1.4577; Double time = calorie burn / (gymnasium player * metric wight); Return Time; } Private Zero displayresults (double _height, double_weight, double oldbmi, double time, double newBmi) {double newWight = _weight - (caloriesBurned / fatCaloriesPerPound); Int pay = (int) _height / 12; Int inches = (int) _height% 12; HeightText.Text = string.Format ("in {0} feet {1}", feet, inches); Weight. Text = _weight.ToString (); OriginalBmi.Text = oldBmi.ToString ("F2"); NewBmi.Text = newBmi.ToString ("F2"); Newwait. Text = new high Toaster ("F2"); ExerciseTime.Text = string.Format ("{0} hours {1} minutes", (int) (time), (int) (time% 60)); } Display results (_height, _weight, oldBmi, time, newBmi);  

The problem appears to be the displayresults method in your call. You are referring to oldbmi, newbmi, and time, but none of these items exists in that area because they are defined to calculate the local level of the BBI. This is an estimate from me - do you really have the code in which you did not show the reference of the calculateBmi phone - but this seems to be the case

If you want oldBmi and newBmi value you calculate . To be usable somewhere else in the program in Displayresults (), you need to create a personal field or public property at the class level, as you have for _height and _weight, after this you set this value to NAVBMI. Instead of making a new double in the radius that you can calculate, which is never used.

Instead, it will appear above your class:

  private double _height; Private double _ weight; Private Double Bulbmi = 0; Private Double Newbie = 0; Const int caloriesBurned = 10000; Constant int running speed = 4; Constant double weightcaleries peerpand = 3500; Const twice double matriculation speed = wining speed / .62137;  

And your calculateBmi method will look like this:

  Personal double calculateBmi (double metricWeight, double metricHyight) {this.oldbmi = metricWyight / Math.Pow (Metric light, 2); Double New Metric Wight = Metric Wight - (Calorie Burn / / (Fat CliplerPand * 2.2046); This.newBmi = newMetricWeight / Math.Pow (MetricHight, 2); Return old; }  

And this display.oldbmi and this.newbmi can call displayresults.

You should know that almost everything in your code. NET is against naming conventions. The variable should not start with '_', the constraints should be Camel Seeds, the private field should be Pascal Cas, and the methods should always have Camel Seeds. Please take a look through this: Many people here follow these conventions and this will be easy for you in future to get help.


Comments