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
Thanks!
Printable View
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
Thanks!
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).
ahh but wat if its a double?
i might as well show you the question to help :D
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 :D
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).