Hi, I am currently newbie in C++, I just learned it for around 2 weeks,
My question is when I put the number, it shows if it's a prime number or not.
The only problem when I put 2 and 3, it supposed to be prime numbers, but the fact that it is not.
Here is my code
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
#define TRUE 1;
#define FALSE 0;
void getNumber(int*);
int isPrime(int*);
int main()
{
int number;
getNumber(&number);
if (isPrime(&number))
cout << "\n" << number << " is a prime number\n";
else
cout << "\n" << number << " is a not prime number\n";
return 0;
}
void getNumber(int *number)
{
// use pointers as parameter, not references
cout << "Please enter a positive number ";
cin >> *number;
if (!cin.good())
{
cout << "Invalid number entered\n";
exit(1);
}
}
int isPrime(int *number)
{
int count, s, i;
/* Every even number is not prime */
if (*number % 2 == 0 || *number % 3 == 0 || (*number < 4 && *number > 1) 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 FALSE;
}
return TRUE;
}
I think the green part need some fixing, can someone pointed out what is my mistakes? THank youu :)