+ 2
Can anyone tell me why it doesn't work? (C++)
include <iostream> using namespace std; int skill(); int main() { int c=skill(); cout<<c; return 0; } int skill(int a=10,int b=10){ int sum= a+b; return sum; }
5 Answers
+ 6
You wrong type function declaration. It does not match the definition you write after main() function
+ 5
Number and types of parameters must match
+ 3
EDIT: I missed your declaration of skill() at the top of your file previously.
Your code should be:
#include <iostream>
using namespace std;
int skill(int a=10,int b=10);
int main() {
int c=skill();
cout<<c;
return 0;
}
int skill(int a,int b){
int sum= a+b;
return sum;
}
+ 1
But if I write "skill" function above int main(), then everything works fine. (I'm new to C++ can't understand why it can't work with "skill" function under int main())
+ 1
Thank you Xan. Such a simple mistake, but so crucial...