English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories


#define n 9999
bool IsPerfect(int n);


main()
{
int j;

for(j = 1; j <=n; j++)
{
if(IsPerfect(n) == TRUE)
{
printf("%d", IsPerfect(n));
}
}
}
bool IsPerfect(int n)
{
int total, i;
total = 0;

for(i=1; i <= n; i++)
{

if(n % i == 0)
{
total += i;


}
if(total == i)
{
return(TRUE);
}
else
{


return(FALSE);
}
}
}


Ok so I get a syntax error on the two lines that have "bool IsPerfect(int n)" and I have no idea why.....help?

2007-10-17 16:16:22 · 5 answers · asked by rcossy1023 2 in Computers & Internet Programming & Design

Ok so I made it "bool IsPerfect()" but now all i get is 0....probably 9999 of them....whats wrong with my math in the IsPerfect function??? too many ifs?

2007-10-17 17:08:21 · update #1

5 answers

It's this: You have a #define n 9999. What this means is that the C/C++ parser (after the preprocessor has done its thing) sees the two bool IsPerfect( int n ) lines as bool IsPerfect( int 9999). You can't have a constant as a formal parameter.

Hope that helps.

2007-10-17 16:42:31 · answer #1 · answered by The Phlebob 7 · 0 0

You seem to have an extra right brace below the "printf("%d", IsPerfect(n)" expression, or above the "bool IsPerfect(int n)" expression. I'm a little rusty on C++, but I seem to recall that you won't encounter errors specifically saying "extra parenthesis" or "extra brace", but they will cause syntax errors. With the extra brace above it makes the compiler think you are trying to close out main() at that step.

2007-10-17 16:21:04 · answer #2 · answered by SoulDawg 4 UGA 6 · 0 1

You didn't provide enough detail. Is this C or C++? What *exactly* is the syntax error you're getting. Also, I'm pretty sure that in both C and C++, the main() function must always return an integer.

You can email me if you need help, but you need to give me more info.

2007-10-17 16:21:43 · answer #3 · answered by gitter1226 5 · 0 0

i don't be attentive to why it truly is happening even though it truly is happeneing to me to so i anticipate it truly is something incorrect with the full internet site! I logged on and had a couplequestions to respond to and have been given an identical message. supply it an hour and see if its back to widely used!

2016-10-13 00:42:42 · answer #4 · answered by ? 4 · 0 0

instead of using #define use

const int n=99999

2007-10-17 17:24:52 · answer #5 · answered by Young Munny 2 · 0 0

fedest.com, questions and answers