Help with FindPrime()
Hello i have this problem with my c++ code, the code dont find the primes.. And i have no idea why.. + im tired :S
So litte help would be nice :)
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 31 32 33 34 35
|
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
// Try all prims start > stop
void FindPrims(int start, int stop){
bool prime; // true or false
if(start > stop)
cout << "Error";
if(start < 2)
cout << "Error";
for(int i = start; i <= stop; i++){
prime = true;
for(int j = 2; j <= sqrt(i); j++){
if(i % j == 0){
prime = false;
}
}
if(prime == true){
} cout << i << " ";
}
cout << endl;
}
int main(){
FindPrims(2, 31);
cin.get();
return 0;
}
|
Thanks!
Edit: Anyway something to improve? I think it loads a long time before it start!
Last edited on
24 25 26
|
if(prime == true){
} cout << i << " ";
}
|
Look at where those curly braces are.
Ops.. Thanks LB!
Topic archived. No new replies allowed.