Will not build, i have no idea why

I'm using Xcode4, and when i try to run the following:

#include <iostream>

int add(int x,int y)
{
return x + y;
}

int main()
{
using namespace std;
cout << "Enter A Number";
int x;
cin >>x;
cout << "And Another";
int y;
cin >>y;
cout << "The Answer is:" << add(x,y) << endl;
return 0;
}

it says "no previous function prototypes for function 'add'"
I'm probably just making some noobish mistake, but it would be appreciated if any of you knew whats wrong
[Code] Tag pls .

It is because you need this before writing add function body
int add(int, int); //function prototypes
after #include <iostream>

Use code::blocks your code is perfect.
Agree. There is nothing wrong with that code. It compiles just fine in VS as well.
@ThangDo: That is only necessary if the implentation of the function is below int main().
Topic archived. No new replies allowed.