Oct 17, 2013 at 1:42am UTC
Im trying to create a program that lists all prime numbers within a range of two number. Can someone please let me know why the below program isn't working?
#include <iostream>
using namespace std;
int main(){
int high_range;
int low_range;
int w;
cout <<"Input highrange here: ";
cin >> high_range;
cout <<"Input lowrange here: ";
cin >> low_range;
for(w=low_range; w>=high_range; w++)
{
if(w%2!=0 && w%3!=0 && w%4!=0 && w%5!=0 && w%6!=0 && w%7!=0 && w%8!=0 && w%9!=0)
cout << w;
}
return 0;
}
Oct 17, 2013 at 5:52am UTC
w>=high_range; w++)
should be w<=high_range; w++)
Oct 22, 2013 at 3:10am UTC
you are correct. thanks for your help.
Oct 22, 2013 at 5:53am UTC
But I think your code does not work properly. You need to implement a function that checks first whether the number is prime or not then print it out.