Calculating the number of primes between 3 and another number This is a simple program that gets a number from a user and calculates the number of primes between 3 and the user's number. I'm just curious if I'm using too many variables. I'm only asking since I'm used to not needing to initialize iterator variables before a loop.

#include &lt;iostream&gt;
using namespace std;
int isPrime(int);
int main() {
    int userValue;
    int b;
    int x;
    char c;
    cout&lt;&lt; "Enter a number : "&lt;&lt; flush;
    cin &gt;&gt; userValue;
    for (x = 3; x &lt;= userValue; x= x+2){
        a = isPrime(x);
        if (a == 1){ 
        b +=1;    
        }
    }
    cout &lt;&lt; "There is, " &lt;&lt; b &lt;&lt; " number of primes from 3 to "&lt;&lt; userValue &lt;&lt; endl;    
    cout &lt;&lt; "hit enter to terminate..."&lt;&lt; flush;
    cin.get();
    cin.get();    
}

int isPrime(int number){
    int i;
    for(i=2; i&lt;number; i++){
    if (number % i == 0 &amp;&amp; i != number) return 0;
    }
    return 1;
}
No, I wouldn't say you're using too many variables (except for c, which doesn't appear to be used anywhere).  Not enough functions, though.  And perhaps too many spurious assignments.  Specifically, I'd suggest something like:

#include &lt;iostream&gt;
using namespace std;

bool isPrime(int);
int countPrimes(int);
int main() {
    int userValue;
    cout&lt;&lt; "Enter a number : "&lt;&lt; flush;
    cin &gt;&gt; userValue;

    cout &lt;&lt; "There are, " &lt;&lt; countPrimes(userValue) &lt;&lt; " number of primes from 3 to "&lt;&lt; userValue &lt;&lt; endl;    
    cout &lt;&lt; "hit enter to terminate..."&lt;&lt; flush;
    cin.get();
    cin.get();    
}

int countPrimes(int number) {
    int result = 0;
    for (int x = 3; x &lt;= number; x += 2){
        if (isPrime(x)){ 
            result++;    
        }
    }
    return result;
}

bool isPrime(int number){
    for(int i=2; i&lt;number; i++){
        if (number % i == 0 &amp;&amp; i != number) return false;
    }
    return true;
}


That will do the same thing as your code.  Also, please consider using variable names that are not just single-letters.