(adsbygoogle = window.adsbygoogle || []).push({}); 1. The problem statement, all variables and given/known data

Ok, I just finished my code for my program. And its not compiling, and im not sure whats wrong.

Below is an image of the errors and the code.

http://i55.tinypic.com/in8x0y.png

And my full code is below here:

MOD NOTE: I indented the code below to make it easier to read.

Code (Text):#include <iostream>

#include <cmath>

using namespace std;

bool isPrime(int x)

{

int divisor;

int maxDivisor;

if (x == 2)

return true;

else if (x % 2 == 0)

return false;

else

{

divisor = 3;

maxDivisor = (int)sqrt(x);

while (divisor <= maxDivisor)

{

if (x % divisor == 0)

return false;

else

divisor = divisor + 2;

}

return true;

}

}

int getIntBetween(int low, int high)

{

if (low<2 || high>2000)

{

return 0;

}

else{

return min + (rand() % (int)(high - low + 1));

}

}

int main()

{

const int MAXPRIME = 2000;

int min;

int limit1;

int limit2;

cout << "Enter the lower limit (2, "<< MAXPRIME << "): ";

cin >> limit1;

min = getIntBetween(2, MAXPRIME);

while (min == 0)

{

cout << "Please Enter a Number Between (2, "<< MAXPRIME << "): ";

cin >> limit1;

min = getIntBetween(limit1, MAXPRIME);

}

cout << "Enter the Upper limit (2, "<< MAXPRIME << "): ";

cin >> limit2;

min = getIntBetween(2, limit2);

while (min == 0)

{

cout << "Please Enter a Number Between (2, "<< MAXPRIME << "): ";

cin >> limit2;

min = getIntBetween(2, limit2);

}

String s = "The primes between "+limit1+" and "+limit2+" are ...\n";

int count = 0;

for (int i=limit1; i<=limit2; i+=2)

{

if (i % 2 == 0)

{

i++;

}

if (isPrime(i))

{

s = s + "i";

count++;

if (count % 5 == 0)

{

s = s + "\n";

}

}

}

cout << s << endl;

cout << "There are " << count << "prime numbers between " << limit1 << " and " << limit2 << endl;

return 0;

}

2. Relevant equations

3. The attempt at a solution

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Homework Help: My C++ simple program is not compiling - Need help, thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**