### I am trying to find the amount of prime numbers between 1-100

Here is my code, for some reason I am getting 51 when the answer is 25. The reason I am using a user made function is because I am going to be expanding the code to 100,000 with segments of 100. Is it my math that is wrong?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758`` ``````#include using namespace std; int isPrime(int number); int main() { int i = 1, amountPrime = 0; bool result; while( i < 100) { result = isPrime(i); if(result == true) amountPrime++; else; i++; } cout << amountPrime << endl; system("PAUSE"); return 0; } //isPrime function int isPrime(int number) { int c; bool isPrime = true; c = number; for(int i = 2; i < c; i++) { if (c % i == 0) isPrime = false; break; } if(isPrime) return true; else return false; }``````
Well, for one, replace the last few lines of the isprime function with:

`return isPrime`

Also, make isPrime return a boolean value, not an integer value.

As for your actual issue, look at the for loop in isPrime(). Specifically, look at the if statement... are you missing something there?
Topic archived. No new replies allowed.