stoyan genchev - 4 months ago 52

C++ Question

I am trying to find out how many times % has substracted a number from another.

For an example if 256 % 50 = 6, then the iterations have been 5? 256 - 50 - 50 - 50 - 50 - 50.

If 145 % 40 = 25, then the iterations have been 3. 145 - 40 - 40 - 40.

I am looking for a solution to the problem without usiong any kind of loop, recursion or goto.

Answer

What you're looking for is the `/`

operator.

Try the division operator instead of the modulus operator. Works every time. It's fundamental math.