determine if numbers are prime

need help with changing it so that its only the numbers between, not including the numbers the user chooses. I cant seem to figure it out. It works right now, but it includes the int one and int two sometimes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;

int main(){
    int one;
    int two;
    
    cout << "Please enter two different numbers and I will tell you what numbers between are not prime numbers." << endl << endl;
    cout << "Enter your first number" << endl;
    cin >> one;
    cout << "Enter your second number" << endl;;
    cin >> two;
    
    while(one <= two){
        if(one%2 == 0){
            cout << one << " is not a prime number." << endl;
        }
        else if((one%3 == 0)&&(one!=3)){
            cout << one << " is not a prime number." << endl;
        }
        else if((one%5 == 0)&&(one!=5)){
            cout << one << " is not a prime number." << endl;
        }
        else if((one%7 == 0)&&(one!=7)){
            cout << one << " is not a prime number." << endl;
        }
        one++;
    }
    system("pause");
}
Last edited on
1
2
3
4
5
6
cout << "Enter your first number" << endl;
cin >> one;
one++;
cout << "Enter your second number" << endl;;
cin >> two;
two--;
Hi Kevin,

Please don't double post - I provided an answer in the other post, only to discover that this one existed as well.

Double posting doesn't mean you will get an answer more quickly, instead it provides a source of aggravation for those who do reply.

Anyway, this is just friendly advice for the future.
Topic archived. No new replies allowed.