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 <iostream>
using namespace std;
int isPrime(int);
int main() {
int userValue;
int b;
int x;
char c;
cout<< "Enter a number : "<< flush;
cin >> userValue;
for (x = 3; x <= userValue; x= x+2){
a = isPrime(x);
if (a == 1){
b +=1;
}
}
cout << "There is, " << b << " number of primes from 3 to "<< userValue << endl;
cout << "hit enter to terminate..."<< flush;
cin.get();
cin.get();
}
int isPrime(int number){
int i;
for(i=2; i<number; i++){
if (number % i == 0 && i != number) return 0;
}
return 1;
}