If abachler's code confused you a little, here it is a little simpler. It will take a bit longer to run though.
Code:
#include <iostream>
using namespace std;
// Prime number function - Tests number for remainder. If none is found, return false. Otherwise, return true.
bool PrimeFunction()
{
int n;
cin >> n;
cin.ignore();
for (int i = 2; i < n; i++)
{
if (n%i == 0)
{
cout << "Number is not prime";
return false;
}
}
cout << "Number is prime";
return true;
}
The code works by testing every factor of a number to see if it has no remainder, and if one such number evenly divides "n," n cannot be prime. You could replace "i < n" with "i * i < n", because you only need to test the factors up to the square root of n. If a factor of n is greater than the square root of n, then its corresponding factor is less than "n" so you would have found it anyways. IE, if n = 15, then you wouldn't need to test the factor "5" because the factor "3" would have been tested already.