10 Oct, 2011, arholly wrote in the 1st comment:
Votes: 0
Hi, I've got another money problem. It seems like whenever I pick up a dollar, it is crediting me with $1.01. I'm guessing it's showing me the wrong amount again, but I'm not sure.
if((num = ch->cents/100) > 0)
{
ch->dollars = ch->dollars + num;
ch->cents = ch->cents - (100 * num);
}

So, if I'm reading this correctly, it looks like it is doing the math wrong (again). It's saying that if NUM, which is cents/100 is greater than 0, then:
dollars = dollars+num
cents = cents - (100*num).

But that doesn't make any cents (see, I have some humor) to me. Dollars shouldn't be being touched, correct? I'm thinking it is displaying it incorrectly again, but not sure.

Can someone please help?

Arholly
10 Oct, 2011, Runter wrote in the 2nd comment:
Votes: 0
That code looks like all it does is converts cents to dollars that a player has. It looks correct to me. If you're having problems my guess is it's originating from somewhere else.
10 Oct, 2011, arholly wrote in the 3rd comment:
Votes: 0
Crud. Well now I'm confused because I seem to have found a bug where it looks like everytime I pick up dollars, $.01 is also picked up and I cannot figure it out for the life of me. Any thoughts on where to start looking?
10 Oct, 2011, Runter wrote in the 4th comment:
Votes: 0
int main() {
int cents = 234;
int num;
int dollars = 0;

if((num = cents/100) > 0) {
dollars = dollars + num;
cents = cents - (100 * num);
}
printf("%d.%d", dollars, cents);
return 1;
}

http://codepad.org/Nk4Ovmku

As this shows, it works as expected. So I think you should figure out why cents is 1 cent higher than it should be. Or look at the code where the cents are being added to the ch->cents value from picking up the item.
10 Oct, 2011, Runter wrote in the 5th comment:
Votes: 0
I think the best advice I can give you is unrelated to this specific problem. If you're unsure about code just create a reduced test case like I did above. You don't have to trust your ability to catch errors by scanning over code. You can test it. You don't even have to use advanced debugging tools, or set up testing frameworks. Just pulling out the lines in question and running them to make sure it's sane is a great way to get to the bottom of what's going on, and to practice writing code since you'll have to refactor it a little bit to get it to work usually. That site I linked to I actually use for a variety of languages, C included. Really, even the best of us can get hung up because of logical assumptions that we don't double check. Then it turns out to be something that a simple test would have found immediately.
10 Oct, 2011, arholly wrote in the 6th comment:
Votes: 0
Good grief, I found the problem. The problem was in the OBJ_VNUM in the area file. Instead of having everything set to 0 for the dollars and cents, everything had a 1 in the cents column, so everything was constantly gaining a penny.

Sorry about that. Thanks for being patient with someone who doesn't know a whole lot.

Arholly
Random Picks
0.0/6