| View previous topic :: View next topic |
| Author |
Message |
Austin Powers Master Cheater
Reputation: -1
Joined: 13 Dec 2008 Posts: 447
|
Posted: Wed May 04, 2011 7:50 am Post subject: Need help solving this |
|
|
Basically, I have an assignment to do for my school project. I can't seem to get it calculate accurately compare to my scientific calculator.
Here it is :
| Code: | Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Result As Double ' Declare "Result" as a Double.
Dim Rounded_Result As Double
Result = (200.MaxValue / 99.9.MaxValue) ^ 2 ' BMI Calculation.
Rounded_Result = Math.Round(Result, 10) ' Round result to 1 decimal place.
BMI_Value.Text = Rounded_Result.ToString ' Display BMI using BMI_Value.
BMI_Message(Rounded_Result) 'Send Rounded BMI result to Sub BMI_Message.
End Sub |
_________________
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed May 04, 2011 9:40 am Post subject: |
|
|
| Code: |
Result = (200.MaxValue / 99.9.MaxValue) ^ 2 ' BMI Calculation.
Rounded_Result = Math.Pow(Result, 2) ' Round result to 1 decimal place.
End Sub |
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
Austin Powers Master Cheater
Reputation: -1
Joined: 13 Dec 2008 Posts: 447
|
Posted: Wed May 04, 2011 9:47 am Post subject: |
|
|
| AhMunRa wrote: | | Code: |
Result = (200.MaxValue / 99.9.MaxValue) ^ 2 ' BMI Calculation.
Rounded_Result = Math.Pow(Result, 2) ' Round result to 1 decimal place.
End Sub |
|
nope. It's still the same. It gives the wrong BMI to me.
_________________
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed May 04, 2011 9:59 am Post subject: |
|
|
Oh sorry, forgot.
| Code: |
Result = (200.MaxValue / 99.9.MaxValue) ^ 2 ' BMI Calculation.
Rounded_Result = Math.Pow(Result, 2) ' Round result to 1 decimal place. |
Should be
| Code: |
Result = (200.MaxValue / 99.9.MaxValue) ' BMI Calculation.
Rounded_Result = Math.Pow(Result, 2) ' Round result to 1 decimal place. |
Remove the ^ 2
(200 / 99.9) ^ 2 on calc = 4.008012016020024028032036040044
Math.Pow((200 / 99.9), 2) = 4.008012016020024028032036040044
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
Austin Powers Master Cheater
Reputation: -1
Joined: 13 Dec 2008 Posts: 447
|
Posted: Wed May 04, 2011 10:17 am Post subject: |
|
|
This is not working T_T. My deadline is on friday. I was trying to make a BMI calculator and I failed. Help me. This is the full thing I was trying to make it work :
| Code: | Public Class Form1
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Result As Double ' Declare "Result" as a Double.
Dim Rounded_Result As Double
Result = (200.MaxValue / 99.9.MaxValue) ' BMI Calculation.
Rounded_Result = Math.Pow(Result, 2) ' Round result to 1 decimal place.
BMI_Value.Text = Rounded_Result.ToString ' Display BMI using BMI_Value.
BMI_Message(Rounded_Result) 'Send Rounded BMI result to Sub BMI_Message.
End Sub
Public Sub BMI_Message(ByVal BMI_Value As Double)
Select Case BMI_Value
Case 0.0 To 15.9
Message.Text = "Severely underweight"
Case 16.0 To 18.4
Message.Text = "Underweight"
Case 18.5 To 24.9
Message.Text = "Healthy weight"
Case 25.0 To 29.9
Message.Text = "Overweight"
Case 30.0 To 34.9
Message.Text = "Obese Class I"
Case 35.0 To 39.9
Message.Text = "Obese Class II"
Case Is >= 40.0
Message.Text = "Obese Class III"
Case Else
Message.Text = "Unable to Determin BMI"
End Select
End Sub
End Class
|
Even the value is not key in, when I clicked calculate, it still gave me the same answer.
_________________
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed May 04, 2011 10:36 am Post subject: |
|
|
You need to add text boxes where the user can enter in their info.
What is .MaxValue?
Not sure about VB but in C# it would be something like.
| Code: |
// Setup your input boxes
// tbWeight
// tbHeight
double result;
double rounded_result;
// Make sure we have a number in textbox
private bool isNumeric(string strNum)
{
double Num;
bool isNum = double.TryParse(strNum, out Num);
if (isNum)
{
return true;
}
else
return false;
}
// in our button click event
if (!isNumeric(tb.Weight.Text) )
{
MessageBox.Show("Please enter a number for weight");
} else if ( !isNumeric(tb.Height.Text) )
{
MessageBox.Show("Please enter a number for height");
} else {
result = (Convert.ToDouble(tb.Weight.Text) / Convert.ToDouble(tb.Height.Text));
rounded_result = Math.Pow(result, 2);
BMI.Value.Text = rounded_result.ToString();
} |
Only thing over your code, is there is a check to make sure the user enters a numeric value as text would throw an exception. I think all you need do is add 2 textboxes, 1 for the users weight and the other for height. then take the values and substitute them in your formula. Instead of 200.MaxValue you would have textBoxWeight.Text and 99.9.MaxValue would be textBoxHeight.Text. You seem to already have the output box where you are writing the value too, just need the user inputs. You are 99% there on your own.
You will still also need to truncate your number to the 1 decimal place. Have a look at NumberFormatInfo class http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.numberdecimaldigits.aspx
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
Austin Powers Master Cheater
Reputation: -1
Joined: 13 Dec 2008 Posts: 447
|
Posted: Thu May 05, 2011 12:07 am Post subject: |
|
|
Here, I forgot.
| Description: |
|
| Filesize: |
19.16 KB |
| Viewed: |
6864 Time(s) |

|
_________________
|
|
| Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Thu May 05, 2011 8:31 am Post subject: |
|
|
Did you get it working?
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri May 06, 2011 3:12 pm Post subject: |
|
|
For metrics, the calculation is:
BMI = ( weight / height ^ 2 )
So:
| Code: | /// <summary>
/// Calculates the body mass index of a person with
/// the given stats. [Use metric types.]
/// </summary>
/// <param name="dbWeight">Weight, in kg, of the person.</param>
/// <param name="dbHeight">Height, in meters, of the person.</param>
/// <returns></returns>
private double CalcBmi(double dbWeight, double dbHeight)
{
// Don't calculate invalid information.
if (dbWeight == 0 || dbHeight == 0)
return 0.0f;
try
{
// 1 meter = 100cm
double dbCentimeters = (dbHeight / 100);
// Calculate as (w / h^2 )
return (dbWeight / Math.Pow(dbCentimeters, 2.0f));
}
catch { return 0.0f; }
} |
The metric calculation converts height to centimeters then multiplies it by itself. So for example, a person with:
Weight: 180 pounds (81.6kg)
Height: 6'3 feet (190.5 meters)
Has a BMI of 22.5 (rounded up). With the calculation being:
81.6 / ( 190.5 / 100 ) ^ 2
_________________
- Retired. |
|
| Back to top |
|
 |
|