[Solved] C++ if x more than y by 3


The expression (x[i] > y) is a boolean, which in this context is casted as an integer (0 or 1), but hardly ever reaches 3. So the branch will always be skipped.

If your values x[i] and y are integers, just take the difference:

if (x[i] - y == 3) {...}

If those are floating point numbers, things are getting more complicated, due to the numbers representation.

EDIT: the same applies to your updated question (if (x[i] - y >= 3) {...}), but the floating point concern might be not that important.

solved C++ if x more than y by 3