Can anyone tell me why it doesn't work? (C++) | Sololearn: Learn to code for FREE!
+ 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; }

12th Apr 2018, 7:26 PM
Shaitzu15
Shaitzu15 - avatar
5 Antworten
+ 6
You wrong type function declaration. It does not match the definition you write after main() function
12th Apr 2018, 7:34 PM
Rull Deef ­čÉ║
Rull Deef ­čÉ║ - avatar
+ 5
Number and types of parameters must match
12th Apr 2018, 7:35 PM
Rull Deef ­čÉ║
Rull Deef ­čÉ║ - avatar
+ 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; }
12th Apr 2018, 8:06 PM
Emma
+ 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())
12th Apr 2018, 7:45 PM
Shaitzu15
Shaitzu15 - avatar
+ 1
Thank you Xan. Such a simple mistake, but so crucial...
13th Apr 2018, 4:14 AM
Shaitzu15
Shaitzu15 - avatar