expected ; or , before }, but at the beginning of declaration?

This will look like homework, but it's not. I'm teaching myself C++, and also college Algebra. For the Algebra, I need to count the number of prime factors of a number, so I thought I'd test my C++ skills and write a quick program to do that for me.

The error I'm getting is at line 8, which is the beginning of the first function declaration. The compiler tells me:
 
primeCount.cpp|8|error: expected ‘,’ or ‘;’ before ‘{’ token|


I'm sure there's something simple that I'm not seeing, but I've been trying to find it for more than an hour, and can't figure out what I'm doing wrong. Here's my code. Any help would be appreciated.

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
#include <iostream>

using namespace std;

int num = 0;

bool isPrime(num)
{
    for ( int i = 2; i < num; i++; )
    {
        if ( num % i == 0; )
        {
            return True;
        }
        else
        {
            return False;
        }
    }
}

int main ()
{
    cout << "Please input number: ";
    cin >> num;

    int prime_count = 0;

    for ( int j = 2; j < num; j++; )
        {
            if isPrime(num) == True;
            {
                prime_count++;
            }
        }

    cout << "\nThe number of prime factors in " num << "is " << prime_count << endl;

    return 0;
}
Last edited on
You need to declare a type for "num" (eg., int, char, double, etc.). In your case, you probably want to declare it as type int.

In for loops, you don't need a semicolon after the last declaration (only between the declarations).

As in, you have this:
 
for (...; ...; ...;) {}

But this is what it is meant to be:
 
for (...; ...; ...) {}


See the "for loop" section in http://www.cplusplus.com/doc/tutorial/control/

EDIT:
Also, true and false aren't capitalized.

EDIT:
All your conditional statements have some kind of problem. Read the link I gave you, it explains them all.
Last edited on
Thank you. I had forgotten that you need to declare type almost everywhere. Your suggestion helped fix it, and I was able to clear up a lot of other errors in the code. (That'll teach me not to code at 1 am.)
Topic archived. No new replies allowed.