HELP!!!! Function definition is not allowed here

im have to a prefect number programme.
It requires to input a positive integer and print the prefect number less than that
Pleaseeee helppp

heres my code
If i input 100 it outputs 117 instead of 6 28 ...
Also it highlighted the line int main() and said function definition is not allowed here . what can i do . thank youuuuu


#include <iostream>
using namespace std;

int Perfect(int posInt){
int total=0;
for (int i=1; i<posInt; i++){
if (posInt%i==0){
total+=i;
return total;
}
}

int main(){
int input, i;
cin >> input;
if (input >0)
i=Perfect(input);
cout << i;

return 0;
}
Last edited on
You seem to have mismatched braces. Check that every beginning brace '{' has a matching ending brace '}' and that you have the same number of beginning braces and ending braces.



Ahhhh thats why
@jlb thanks i hv added the missing }
But whats wrong with my programme to print the prefect number? I still cant work that out
Last edited on
It appears that your for() loop only runs once.

Topic archived. No new replies allowed.