Stuck somewhere

Greetings everyone,
I'm a novice to C++, just started working with it a couple of days ago. I wrote a program that computes the sum of all integers between 1 and 100 that have a remainder of 2 when divided by 3, 5 or by both. Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
using namespace std;

int main() {
    int x, div1, div2, result = 0;
    for (x = 1; x <= 100; x++) {
        div1 = x % 3;
        div2 = x % 5;
        if (div1 == 2 and div2 == 2 or div1 == 2 or div2 == 2) {
            result += x;
        }
    }
   cout << result;
}

Is there a way to enhance this code?

Another question; I have been trying to write a program that prints all the three digit integers that use three distinct digits from a set, ie {1, 2, 3, 4, 5, 6, 7}. It should print 123, 324, 567, 712 but not 773 or 333.
Thanks in advance
Last edited on
There are no and/or keywords in c++. see http://www.cplusplus.com/doc/tutorial/operators/ logical operators.
Also, "div1==2 or div2==2" already covers the case when div1 ==2 and div2==2.

edit: about the other problem.
1
2
3
4
for(firstnumber = 1; firstnumber<10; firstnumber++){
    for(secondnumber = 0; secondnumber<10;secondnumber++){
        if(secondnumber!=firstnumber){
           for(third number//and so on... 
Last edited on
Thank you. I'm using the Code::Blocks 8.02 compiler and it accepts and and or keywords; I replaced them with && and || though.

Thanks again for your help
Topic archived. No new replies allowed.