# a math problem . . . i hope atleast

• 05-26-2002
blight2c
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:D 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:
Quote:

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 :)
• 05-26-2002
Salem
> 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.
• 05-26-2002
Mario
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));}
• 05-26-2002
blight2c
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 :D
• 05-26-2002
Boksha
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.
• 05-26-2002
Salem
if (fv_mgrDirection=='b'||'B')

is

if ( fv_mgrDirection == 'b' || 'B' != 0 )
• 05-26-2002
Sebastiani
geez, how hard is it to convert the char to upper- or lower-case and then simply compare it like that?
• 05-26-2002
blight2c
i see (says the blind man ineptly typing at his very expensive toy)

thanks a lot guys :D