C++ incorrect output summing multiples [Solved]
Passes some tests in Code Coach but not all. /* You need to calculate the sum of all the multiples of 3 or 5 below a given number. Task: Given an integer number, output the sum of all the multiples of 3 and 5 below that number. If a number is a multiple of both, 3 and 5, it should appear in the sum only once. Input Format: An integer. Output Format: An integer, representing the sum of all the multiples of 3 and 5 below the given input. Sample Input: 10 Sample Output: 23 */ #include <iostream> using namespace std; int main() { int sum = 0; int x = 1; int y; cin >> y; while(x<=y){ if((x % 5 == 0) != (x %3 == 0)) { sum += x; } x += 1; } cout<<sum<<endl; return 0; } If 100 is entered output is 2103 but should be 2318. Can anyone point out the error?