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.
#include <iostream>
usingnamespace 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;
}
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.)