Tutorial :How to wrap this value?



Question:

Example: I have a scale between 1 and 7. When I get a value like 8, I want it to be wrapped on that scale so it's converted to 1. More examples:

  • 1 results in 1
  • 5 results in 5
  • 7 results in 7
  • 8 results in 1
  • 9 results in 2
  • 10 results in 3
  • 11 results in 4
  • 12 results in 5
  • 13 results in 6
  • 14 results in 7
  • 15 results in 1
  • 16 results in 2

and so on.

Is there a method or useful C-function to do that? Something tells me I just need a modulo. It's 42°C in my room. My brain is like soap.


Solution:1

int b = ((a-1) % 7) + 1;

Check using Excel, of all things!

Yes it's HOT today.. arrgh!


Solution:2

Try ((number - 1) % 7) + 1.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »