I've actually reformatted it so it doesn't give compiler warnings for parentheses:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
#include <iostream>
using namespace std;
int main()
{
int i;
cout << "Enter a number\nNumber: ";
cin >> i;
if (((i % 5 == 0) && ((i / 100) != 6)) || ((i % 5 == 0) && ((i / 10) % 10 != 6)) || ((i % 5 == 0) && ((i % 10) != 6)))
cout << "Output: bizz" << endl; // bizz is divisible by 5 and doesn't have a 6
else if (((i % 5 != 0) && ((i / 100) == 6)) || ((i % 5 != 0) && ((i / 10) % 10 == 6)) || ((i % 5 != 0) && ((i % 10) == 6)))
cout << "Output: buzz" << endl; // buzz is not divisible by 5 however it does have a 6
else if (((i % 5 == 0) && ((i / 100) == 6)) || ((i % 5 == 0) && ((i / 10) % 10 == 6)) || ((i % 5 == 0) && ((i % 10) == 6)))
cout << "Output: bozz" << endl; // bozz is divisible by 5 and has a 6
else cout << i << endl; // i is neither divisible by 5 nor does it have a 6
return 0;
}
|
And here's the thing - I think you're taking too many commands in your initial "bizz" call, and the call also contradicts itself. Now please remember, this is based on MY UNDERSTANDING of what you have in the first if statement, and I could very well be wrong, but it looks like:
i divisible by 5 or 0 and not 600, or i divisible by 5 and 0 and not 606, or i divisible by 5 or 0 and not 66.
And to be perfectly honest, this is really confusing code. We both agree on that much, right? But anyway, the problem is you're wanting to remove, say, 600 from the first statement, but it's perfectly acceptable because of the other calls. That's to say, it's finding the first call invalid, but it has two more options that are perfectly valid (if I'm understanding this right... the i / 10 % 10 != 6 I'm shaky on, but the last function is perfectly acceptable for 600), so you're saying, "I'm not going to allow 600 in the first if statement... except I kind of am..." and it's strange.
EDIT: And in the case of your code - ESPECIALLY this code - I would probably be very explicit in the first line to remove values not ending in divisible by 5 or ending in 6 from the very start with:
|
if (i % 5 != 0 || i % 2 != 0) { cout << i << endl; }
|
And just be done with it right then and there, since it would be an odd number that isn't 5 right from the start. Normally I'd reserve that for the end, but in the case of this very confusing code I think it prudent to just terminate the program ASAP for values we know we don't want.