Why, when using the operator, the software enters the block if and when using the pre-operator программа, it doesn't.
-
Why when I write
while (num>0) { if (num % 10 != 3 && num % 10 != 6) { OriginNum += num % 10 * check; check *= 10; } num /= 10; } }
Then, at num%10, it'll be 3 or 6, it won't in the block if it's in the block. and when in lieu of " produce &
while (num>0) { if (num % 10 != 3 || num % 10 != 6) { OriginNum += num % 10 * check; check *= 10; } num /= 10; } }
The program enters if the num%10 is 3 or 6
In the first case, 6 are not equal to 3 and 6, the result is false (not entered if) a In the second case, checks 6 not equal to 3 or 6 - the result is also false because 6=6
So again the question is why in the second case the result is not false and the programme comes in if
Who needs the whole code.
#include <iostream>
using namespace std;
int main(void) {
int num, OriginNum=0;
int check=1;cout << "I can output number without 3 and 6" << endl; cout << "Enter number:"; cin >> num; while (num>0) { if (num % 10 != 3 || num % 10 != 6) { OriginNum += num % 10 * check; check *= 10; } num /= 10; }
}
-
If number not 3 or 6 - but it could be like that, right?
If number not 3 or 6 - Whatever number we've got, it's either three or six or three or six. I mean, it's always true. ♪
Если это 3 — оно не 6, ура! Если это 6 — оно не 3, снова ура :) Если это 1,2,4,5,7 etc — оно таки не 3, и дальше можно и не проверять.
Is that clear?
See also https://ideone.com/2LgmaD