Thread: a math problem . . . i hope atleast

  1. #1
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266

    a math problem . . . i hope atleast

    hey all, hope you're having a good weekend. one of my functions isn't returning what i think should be a proper value, so i was hoping to post it, surf around a bit, and then someone will by magic solve all my problems and i don't have to do the work will that person be you?

    here's the function:
    Code:
    int Player::mf_playerStats_battingAve(char fv_mgrDirection)
    {
    //bunt
    	if (fv_mgrDirection=='b'||'B')
    	{return ((2*bat_aim)+bat_str+(rand() % lck));}
    //left grounder
    	if (fv_mgrDirection=='l'||'L')
    	{return ((bat_str)+(.75*bat_aim)+(rand() % lck));}
    //right grounder
    	if (fv_mgrDirection=='r'||'R')
    	{return ((bat_str)+(.75*bat_aim)+(rand() % lck));}
    //sacrafice fly
    	if (fv_mgrDirection=='s'||'S')
    	{return ((bat_aim)+(bat_str)+(rand() % lck));}
    //homerun********should run this if*************
    	if (fv_mgrDirection=='h'||'H')
    	{return ((.5*bat_str)+(bat_aim)+(rand() % lck));}
    //default
    	else
    	{return ((.5*bat_str)+(bat_aim)+(rand() % lck));}
    }
    here's the values acording to the debugger:
    bat_aim 10
    bat_str 10
    fv_mgrDirection 104 'h'
    lck 10
    + this 0x0012ff48
    rand returned 29372
    so, as i see it the equation should read:

    (.5*10)+(10)+(2)==19, right?

    well, on this occasion it came up with 32. all the returned values tend to be in the low 30's. so what gives? what am i missing? thanks in advance

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > all the returned values tend to be in the low 30's. so what gives?
    You're in the wrong if/else that's what

    > if (fv_mgrDirection=='b'||'B')
    This is always true.

    Perhaps you mean't
    if ( fv_mgrDirection=='b' || fv_mgrDirection== 'B' )

    > here's the values acording to the debugger:
    Yeah, and if you had pressed 'step' a couple of times, you would have seen it take a completely unexpected branch through the code.

  3. #3
    Registered User Mario's Avatar
    Join Date
    May 2002
    Posts
    317
    I didn't look at the details yet. But just to let you know 32 is the result for:

    if (fv_mgrDirection=='b'||'B')
    {return ((2*bat_aim)+bat_str+(rand() % lck));}
    Regards,
    Mario Figueiredo
    Using Borland C++ Builder 5

    Read the Tao of Programming
    This advise was brought to you by the Comitee for a Service Packless World

  4. #4
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    thanks for helping

    >> if (fv_mgrDirection=='b'||'B')
    This is always true.

    how is that always true? and what's difference between that and:

    >if ( fv_mgrDirection=='b' || fv_mgrDirection== 'B' )

    i can't quite understand. thanks again

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    125
    Well, 'B' is always true. You have to see it like this:
    ((fv_mgrDirection=='b') || ('B')) instead of (fv_mgrDirection==('b' or 'B'))
    Since B is always more than 0 (it's about 90-140 or so), the || will always return 1.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    if (fv_mgrDirection=='b'||'B')

    is

    if ( fv_mgrDirection == 'b' || 'B' != 0 )

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    geez, how hard is it to convert the char to upper- or lower-case and then simply compare it like that?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    i see (says the blind man ineptly typing at his very expensive toy)

    thanks a lot guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 04-22-2009, 02:35 AM
  2. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  3. more of a math problem :-/
    By linucksrox in forum C Programming
    Replies: 2
    Last Post: 04-08-2004, 12:23 AM
  4. math problem
    By unixOZ in forum Linux Programming
    Replies: 4
    Last Post: 10-19-2002, 12:17 AM
  5. Please help me with a math problem
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 10-07-2002, 01:42 PM