Hello, I'm in my second week of an intro to comp sci class and we're learning C++. I've been working on a homework assignment for the past few days with no avail. The assignment is the following:
Write an algorithm (using input/output, assignments, conditionals, and loops) to find the sum of all positive integers less than 1,000,000 that are divisible by 3 but not by 6.
So far I have come up with this:
#include <iostream>
using namespace std;
int main()
{
int sum=0;
int x=0;
while
(x<=1000)
x=x+1;
if (x%3==0 && x%6!=0)
{
sum=sum+x;
cout<<sum<<endl;
}
return 0;
}
The first part of the program seems to run fine, but when it gets to the if statement nothing happens. I've asked classmates and otherwise for ideas and help but they were just as stumped as myself. I've emailed the teacher, but just in case I figured I'd looked elsewhere for solutions as well. I'm not looking for the answer, just guidance in the right direction. Thanks for any help in advance!