Using bool to show prime numbers

So my program is supposed to do this "Write a function name isPrime, which takes an integer as an argument and returns true if the argument is a prime number, or false otherwise." , other requirements were to use bool, and to also name the previous prime numbers to the number that was inputted. I have been able to do that part, I just cant get the bool variable to work to tell me to be able to have the program show if it is a prime number or not. I need help to find where i am making the mistake in the program, thank you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
// function prototype
bool isPrime(int);

int main()
{
	int number;
	cout << "Please enter any positive integer below 3001" << endl;
	cin >> number;

	isPrime(number);
	if (isPrime(number)) {
		cout << number << " is a prime number" << endl;
	}
	else {
		cout << number << " is not a prime number" << endl;
	}
	return 0;
}
bool isPrime(int number)
{
	int found = 0, count = 0;
	
	for (int i = 2; i < number; i++)
	{
		for (int j = 2; j < sqrt(i); j++)
		{
			if (i%j == 0)
				count++;
		}
		return true;
		if (count == 0 && i != 1)
		{
			found++;
			cout << "Prime Numbers before,  " << i << endl;
			count=0;
		}
		count = 0;
	}
	
}
Lines 33 to 39 will never happen, because your function returns before then. Your function basically always returns true. What about when the number isn't a prime number?

would a if else statement in the bool isPrime function solve the problem? that is what i am stuck on, that the program never gives me an output for when the number is not a prime number.
Topic archived. No new replies allowed.