You can not define function inside main function .
Please check this :
int f(int n){ int p; if(999 % n == 0){ p=999/n; } else if(999 % n !=0){ p=(999-(999 % n))/n; } return n*(p*(p+1)/2);}
int main(){ std::cout<<f(3);
return 0;}
int main(){ int x;int f(int n){ int p; if(999 % n == 0)
{ p=999/n; } else
{ p=(999-(999 % n))/n; } return n*(p*(p+1)/2);}x=f(3); //As the fn is returning a value, it must be held by some other temp varbl of same return typecout<<x;}
{ p=(999-(999 % n))/n; } return n*(p*(p+1)/2);}x=f(3); //As the fn returns a value,it must be held somewhere in the // memory by a temp variable. cout<<x;}