Simple stuff, need help plz? functions etc

Can anyone explain to me this code ? I wrote it but I copied some from another source. It won't compile due to a linker error in dev c++, but I'm sure I did it write. I don't understand the concept of functions. for e.g "int factorial (int) <-- why is there (int) there again? And if it was int (x, y) what purpose do they serve? ty..

#include <iostream>
using namespace std;
int factorial (int);
int main()
{
int result;
cout << "Enter a number to calculate the factorial, then press ENTER: ";
cin >> result;
cout << "The factorial of " << result << "is" << factorial (result) << endl;
}

int factorial (int n)
{
int fact = 1;
if (n <= 1)
return 1;
else
fact = n * factorial (n - 1);
return fact;
}
closed account (o1vk4iN6)
I already responded to your other topic... http://cplusplus.com/forum/general/59342/
Discard Dev C++, use CodeBlocks instead. I see that your knowledge of functions is not complete. You should read some books. try this link http://www.cplusplus.com/doc/tutorial/functions/
Also, there is "int" in the function because its a declaration of the function. While declaring you can omit the name of the parameters.

1
2
3
4
5
6
7
8
9
//For declaration
int factorial(int);

//and

int factorial(int n);

//both are valid
@Xerzi I read your post but didn't really understand what you meant but I think I got a better idea now thx .
Topic archived. No new replies allowed.