# Thread: a math problem . . . i hope atleast

1. ## 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. > 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. 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));}

4. 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. 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. if (fv_mgrDirection=='b'||'B')

is

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

7. geez, how hard is it to convert the char to upper- or lower-case and then simply compare it like that?

8. i see (says the blind man ineptly typing at his very expensive toy)

thanks a lot guys