Jump to content
  • Advertisement
Sign in to follow this  
Handyman54

Helping people new at programming!

This topic is 4623 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 =)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
floats and doubles have a limited precision resulting in inaccuracies

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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").

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!