0

Help me please. I can not solve the Divisible problem. Tests # 2 and 4 fail.

My attempt: https://code.sololearn.com/cNUsB7IAh8Ba/?ref=app

17th Jun 2020, 5:09 PM
Тимофей Орловский
8 Respostas
0
You haven't actually posted a link to the tutorial itself. But I think I know what the problem is. In line no. 10, if (!(x % 3 && x % 6)) I think you want to check if it is divisible by both 3 and 6. If so then the expression inside the paranthesis checks if x % 3 is not 0 and x % 6 is not 0, and then the ! operator reverses it. So if you remove the !, it should work.
17th Jun 2020, 5:15 PM
XXX
XXX - avatar
0
Output: no output
17th Jun 2020, 5:17 PM
Тимофей Орловский
0
Тимофей Орловский I am really sorry, you should actually keep the ! operator. The problem is with the paranthesis. It should be if (!(x % 3) && !(x % 6)) That is, it should check if x % 3 is 0 and x % 6 is zero.
17th Jun 2020, 5:21 PM
XXX
XXX - avatar
0
#include <iostream> #include <cmath> using namespace std; int main() { int x = 0; cin >> x; if (x % 6 != 0) { if (!(x % 2 && x % 3)) { cout << "divisible by all"; } else { cout << "not divisible by all"; } } return 0; } fail #2 and #4
17th Jun 2020, 5:37 PM
Тимофей Орловский
0
Подумайте о ситуациях, когда число делится на 2, а не на 3 или наоборот.
17th Jun 2020, 6:10 PM
Anubhav Mattoo
Anubhav Mattoo - avatar
0
При #include <iostream> #include <cmath> using namespace std; int main() { int x = 0; cin >> x; if (x % 3 != 0) { if (!(x % 2 && x % 6)) { cout << "divisible by all"; } else { cout << "not divisible by all"; } } return 0; } //ничего не выводит.
17th Jun 2020, 7:31 PM
Тимофей Орловский
0
Тимофей Орловский did you try replacing if (!(x % 2 && x % 3)) { with if (!(x % 2) && !(x % 3))
18th Jun 2020, 4:50 AM
XXX
XXX - avatar
0
With the number 789, it should print not Divisible, but it prints Divisible
18th Jun 2020, 6:56 AM
Тимофей Орловский