Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Need help solving this

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Austin Powers
Master Cheater
Reputation: -1

Joined: 13 Dec 2008
Posts: 447

PostPosted: Wed May 04, 2011 7:50 am    Post subject: Need help solving this Reply with quote

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
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed May 04, 2011 9:40 am    Post subject: Reply with quote

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
View user's profile Send private message
Austin Powers
Master Cheater
Reputation: -1

Joined: 13 Dec 2008
Posts: 447

PostPosted: Wed May 04, 2011 9:47 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed May 04, 2011 9:59 am    Post subject: Reply with quote

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
View user's profile Send private message
Austin Powers
Master Cheater
Reputation: -1

Joined: 13 Dec 2008
Posts: 447

PostPosted: Wed May 04, 2011 10:17 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Wed May 04, 2011 10:36 am    Post subject: Reply with quote

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
View user's profile Send private message
Austin Powers
Master Cheater
Reputation: -1

Joined: 13 Dec 2008
Posts: 447

PostPosted: Thu May 05, 2011 12:07 am    Post subject: Reply with quote

Here, I forgot.


Capture.PNG
 Description:
 Filesize:  19.16 KB
 Viewed:  6864 Time(s)

Capture.PNG



_________________
Back to top
View user's profile Send private message MSN Messenger
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu May 05, 2011 8:31 am    Post subject: Reply with quote

Did you get it working?
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri May 06, 2011 3:12 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites