How many prime numbers between 1 - N

I'm new to the whole programming stuff. If anyone can help me on this that would be awesome.

I have to create a program that will tell me how many primes numbers there are between 1 and N. The max value is 50,000 and I have to use 2 void functions

What I have so far is

#include <iostream>
using namespace std;
-I know I have to insert void function here-
int main ()
{
char reply = 'y';
while (reply =='y' || reply == 'Y')
{
cout << Continue?";
cin>> reply;
}
return 0;
}
-void functions-

Like for example my output would be:
"The amout of prime numbers between 1 and N is: -value-"
(The amount of prime numbers 1 and 10 is: 5)

Thank you in advanced to all that helps me on this :)
Last edited on
add this function to your program

1
2
3
4
5
6
7
8
9
10
11
12
13
14
void prime_num(int N) //int N will be inputted by user
{
int count=0;
for(int i=2;i<=N;i++)
{
if(N%i!=0)
{
count++;
continue;
}

}
cout<<"The number of prime between 1 and "<<N<<" are: "<<count;
}
Last edited on
Why void functions? Are by reference parameters allowed?

@programmer007: Recheck your logic. Your code doesn't do primes.

Line 13 could be in "void function".
Whoops! edited now... Thanxx @keskiverto
I have to
1. Create a void function to get the user input
2. Create a function to find the number of prime numbers from 1 max_number
3. Create a function to load primes into an array
4. Create a void function to output the values to the screen using this array

Thank you for the help!
Topic archived. No new replies allowed.