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.
int b = ((a-1) % 7) + 1;
Check using Excel, of all things!
Yes it's HOT today.. arrgh!
Try ((number - 1) % 7) + 1
.
精彩评论