Thread: need help on formula?

  1. #1
    Registered User
    Join Date
    Mar 2011

    need help on formula?

    hey guys
    im just wondering if theres a function/formula to add 2 to every 100 the user put.
    so if its 129 add 2 or if its 299 add 4 etc

  2. #2
    THANK YOU KINDLY SIR Phenax's Avatar
    Join Date
    Mar 2011
    Use the power of integer division!

    int addNum = 2*(userInput / 100);

    With integer division, 555/100 would be 5, for example. Then you multiply that by two. Integer division basically just drops the decimal (or floors the number).

  3. #3
    Registered User
    Join Date
    Mar 2011
    ahh but wat if its a double?
    i might as well show you the question to help
    3 Long-term benefits (LTB) are charged at $2 per every full $100 of gross weekly earnings to a maximum LTB payment of $100 per week. An example of a gross weekly pay of $163 will result in a $2 LTB deduction, as there is only one full $100 amount. Make sure you understand the requirement.
    thanks again

  4. #4
    Registered User
    Join Date
    Jun 2005
    If it's a double, either convert to an integer first (applicable if your value is guaranteed to fit into an integral type) or use the floor() function (which is general, within basic limits of floating point precision).
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zeller's Formula
    By unejam2005 in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2005, 09:48 PM
  2. how to change char to formula
    By kosong in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 04:31 AM
  3. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 05:22 AM
  4. Need help with this formula -b/2a..Please read.
    By foofoo in forum C Programming
    Replies: 4
    Last Post: 06-04-2002, 11:59 PM
  5. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 08:28 PM