HELP!!!!!!!!!! outputting primes within multiple sets of numbers

I am suppose to calculate and display the number of primes in the first 50 “chiliads”. I can easily find a prime or count of primes, but I cannot display the individual count of primes between required sets of two numbers on the screen.


#include <iostream>
#include <cmath>
#include <iomanip>


using namespace std;

bool isPrime(long n);
long primeCount(long x, long y);
void printChiliads();
long cntPrime = 0;
long totPrime = 0;
long (list);

int main()
{
char reply;
int count = 0;
long x = 0;
long y = 0;
bool done;



for (x = 1; x <= 49001; x++)

x + 1000;


for (y = 1000; y <= 50000; y++)










cout << x << "-" << y << endl;

cout << "Press q (or any other key) followed by 'Enter' to quit: ";
cin >> reply;
}



bool isPrime(long n)
{
long i;

if (n <= 1)
return false;
for (i = 2; i < n; i++)
{
if (n % i == 0)
return false;
}
return true;
}

long primeCount(long x, long y)
{
long count = 0;
for (long i = x; i <= y; i++)
{
if (isPrime(i))
count++;
}
return count;
}]
Last edited on
my program needs to display:


start End Number of primes

1 1000 (number of primes found to be printed here)

1001 2000 ( number of primes found to be printed here)
.
.
.
.
.
49001 50000 (number of primes found to be printed here)
I wonder where the problem is? Take this:
1
2
3
4
5
6
7
8
9
10
long primeCount(long x, long y)
{
long count = 0;
for (long i = x; i <= y; i++)
{
if (isPrime(i))
count++;
}
return count;
}
and change it somewhat:
1
2
3
4
5
6
7
8
9
10
long primePrint(long x, long y)
{
long count = 0;
for (long i = x; i <= y; i++)
{
if (isPrime(i))
cout << i;
}
return count;
}
and it will print the prime numbers instead of just counting them
Last edited on
Topic archived. No new replies allowed.