Bool Function named isPrime

I'm having a few problems. The question is:
A prime number is an integer greater than 1 that is evenly divisible by only 1 and itself. For example, the number 5 is prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided by 1, 2, 3, and 6.

Write a Boolean function named isPrime, which takes an integer as an argument and returns true if theargument is a prime number, and false otherwise.


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
 #include <iostream>
	using namespace std;

bool is Prime(int num;)
	int main ()
{	
int num=0;
	
	cout << "enter a number:  ";
cin >> num;

if (isPrime(num) == true)
	cout << num << "is prime";
if 
cout << num << " is not prime";


return 0;
}
bool isPrime(int input)
{
	if(input<1)
		return false;
	 else if (input == 1||input == || input==3)
	{
		return true;
	}
	else
	
		for(int i=2; i<input; i++)
		{
			if(input%i==0)
				return false;
}
		return true;
	}
}


Errors:
main.cpp:30: error: expected initializer before 'Prime'
main.cpp: In function 'bool isPrime(int)':
main.cpp:50: error: expected primary-expression before '||' token
main.cpp:56: error: expected `(' before 'for'
main.cpp:56: error: 'i' was not declared in this scope
main.cpp:56: error: expected `;' before ')' token
main.cpp: At global scope:
main.cpp:62: error: expected declaration before '}' token
line 4 - semicolon should be outside the closing parenthesis in the function prototype and no space between is and Prime

line 14 - did you mean this to be an else instead of if?

line 24 - missing part of the middle condition

line 37 - extra bracket

Edit: if prime should be greater than 1, 1 shouldn't be come back with an "is prime" message
Last edited on
The answer said it didn't have an else in the solution.
Topic archived. No new replies allowed.