-2

Below is my code for printing prime numbers up to a given input by user. However, my calculations are not working correctly and my output is printing twice. Any idea? :sad:

```
#include <iostream>
#include <cmath>
using namespace std;
void prime_num(int);
int main()
{
cout << " Enter a number and I will generate the prime numbers up to that number: ";
int num = 0;
cin >> num;
prime_num(num);
}
void prime_num( int num)
{
int check_prime = 0;
for ( int i = 0; i <= num; i++)
{
check_prime = 1;
for ( int j = 2; j <= i/2; j++)
{
if ( i % j == 0 )
check_prime = 0;
if ( check_prime != 0 )
{
cout << i << endl;
}
}
}
}
```

*Edited 3 Years Ago by pyTony*: fixed formating