Helping people new at programming!

Started by
19 comments, last by gav86 18 years, 5 months ago
Hi all! I would like to tell any newbies to programming that i am willing to help with any problems you are having! I am new at programming also but I am learning more every week at my school. I right now at this time am making a text adventure. So if you have any questions just call on me! P.S. does anyone know how to put a random monster generator and how to subtract as in money? It's for my game. I just need a refresher on that! Thanks all
Advertisement
Quote:Original post by Handyman54
Hi all! I would like to tell any newbies to programming that i am willing to help with any problems you are having!

Great!
Quote:P.S. does anyone know how...subtract?

While I admire your willingness to help, Handyman, keep in mind that sometimes it is more helpful to remain silent then to offer up guesses that aren't supported by experience. Learning to tell good advice from bad is a very difficult skill for a lot of people, and many of those people are in the For Beginners forum. The best thing you can do for these people is concentrate on learning yourself, so that you can better help them in the future.
I would imagine that if you were using the modern day american system, you would either multiply the amount by 100 and get how much cents, or use one int for the dollar amount and one for the cents, trying to avoid floats as much as possible.
Quote:Original post by ender7771trying to avoid floats as much as possible.


....Why?

Id either just use a float, or probably better still just store the amount in cents, which you can then display as dollars/cents fairly easy. You could even write a little class that handles it all (and overload the + - operators...)

Handyman, being available to help others is always a good thing. Just be sure your not ever giving out bad or incorrect advice ;) Spend some time making sure you fully understand everything your doing first =)
"Leave it to the computer programmers to shorten the "Year 2000 Millennium Bug" to "Y2K." Isn't that what caused this problem in the first place?"
floats and doubles have a limited precision resulting in inaccuracies
Quote:Original post by Anonymous Poster
floats and doubles have a limited precision resulting in inaccuracies


Well, its only ever gonna need to go to 2 decimal places. As long as your not allowing inputs like $53.35436789 there shouldnt be a problem...
"Leave it to the computer programmers to shorten the "Year 2000 Millennium Bug" to "Y2K." Isn't that what caused this problem in the first place?"
Not true. 53354367.89 would be just as big a problem as 53.35436789 is.
It doesn't really matter how many decimal places you have, it's how many digits total (and even that's not the full story. You can get inaccuracies with much shorter numbers too. Like, say, 2.1)

If you use doubles/floats, you *will* get rounding errors. The question is whether that's a problem in your case.
I brought up the fact that you should stay away from floats because I recall a while back (maybe like a month or so) someone had a program that figured out change. The algorithm was great and everything, but because there was floats the rounding errors made the program bad. Anyone else remember?
Quote:Original post by ender7771
I brought up the fact that you should stay away from floats because I recall a while back (maybe like a month or so) someone had a program that figured out change. The algorithm was great and everything, but because there was floats the rounding errors made the program bad. Anyone else remember?

Yeh, I remember. Basically, the problem was that successive subtractions were producing a number that was something like 1.999999997 instead of 2, and this was screwing up the change-making algorithm.

Floating point numbers should never be used as counts ("three apples"), only as amounts ("two cups of sugar").
But integers have a far-larger rounding error than floats!(or doubles) I don't understand why using an integer will make your rounding problems go away. (Not that anyone has stated having a rounding error yet)

As for your questions, were going to need a little more information on that. Theres the rand() function if youre using c++. That will generate a random number. Just run that and an Integer through a modulus operator and you can generate a fairly-random number between 0 and the Interger - 1. As for subtracting, you could use the subraction operator if its for intergers/floats...

This topic is closed to new replies.

Advertisement