Alright so here is the jist I need to make a programm that inputs a number and checks if the number entered is a prime number. I got the programm to work (without pointers) but the requirement is i HAVE to use pointers.

I read up on points, did the class examples, they work out fine, tried apply the same princple to this question and alas it does not seem to work.

the code is as follows:

#include <iostream>
#include <math.h>

#define TRUE 1;
#define FALSE 0;

using namespace std;

int isPrime(int);
void getNumber(int);

int main()
	int n=0;
	getNumber(&n); //line 16

	if (isPrime(n))
	 cout << "\n" << n <<" is a prime number\n";
	 cout << "\n" << n <<" is not a prime number\n";
	return 0;

void getNumber(int *number)
	//number = 0;
	cout << "Please enter a positive number ";
	cin >> *number;
	if (!cin.good())
		printf("Invalid number entered\n");

int isPrime(int number)

int count, s;

/* Every even number is not prime */
if (number % 2 == 0) return FALSE;

/* check every odd number up to the square root of the number */
s = sqrt(number);
for (count=3; count <=s; count+=2)
	if (number % count == 0) return TRUE;
return FALSE;


When i compile i get this error:

Error: line 16: Invalid conversion from int* to int

Any idea on how to fix this?

10 Years
Discussion Span
Last Post by Ancient Dragon
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.