-3

I need to check of a number is incremented by 10 (70, 20, 110)

example: input: (74, 21, 105) output: false

input: (70, 20, 110) output: true

I have tried if(num % 10 == 1)

  • 6
    Try `if(num % 10 == 0)` and in future please put a bit more effort into working things like this out for yourself. –  Apr 17 '17 at 14:20
  • 1
    1. there is no question, 2. read on what `%` does.100%10 equals 0 – Fureeish Apr 17 '17 at 14:20
  • 1
    I suggest *subtracting* the numbers, subtract the first from the second. If the difference between two numbers is 10, then the second is incremented by 10. – Thomas Matthews Apr 17 '17 at 14:30
  • All of the members of `(70, 20, 110)` are _divisible_ by 10, but why should that list pass a test called _incremented_ by 10? What do you think "increment" means? – Solomon Slow Apr 17 '17 at 17:03

1 Answers1

2

The remainder operator (%) is indeed what you're looking for.

The binary operator % yields the remainder of the division of the first operand by the second (after usual arithmetic conversions).

The remainder you're looking for is zero, not one. Therefore the correct check is:

if(num % 10 == 0)
Vittorio Romeo
  • 90,666
  • 33
  • 258
  • 416