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";
	else
	 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");
		exit(1);
	}
	
}

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?

see line 10: it has the wrong prototype. Compare it with line 25 which is correct.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.