is this correct?

I need a program that prints the sum of numbers up to a 1000 and is divisible by 3 only not four or five.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  #include <iostream>

using namespace std;


int main()
{
	float sum = 0.0;
	
	
	for (int i = 1; i <= 1000; i++)	
	{
		if (((i % 3) == 0) && ((!i % 4) == 0) && ((!i % 5) == 0))
		{
			sum = sum + i;
		}
	}
	cout << "The sum of numbers up to a thousand and only divisible by 3:\t" << sum << endl;
	system("pause");
}
(!i % 4) == 0
But which is evaluated first, the 'logical not' or the 'modulo'? C++ has clear operator precedence rules, and the answer is 'logical not'. Therefore, we can add more parenthesis without changing the expression:
( (!i) % 4 ) == 0
But what is NOT i? When is it divisible by 4?

How about:
0 != (i % 4)
Topic archived. No new replies allowed.