Who can say what's wrong with this code?(C++) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Who can say what's wrong with this code?(C++)

https://code.sololearn.com/cOM1Y8W0SgGq/?ref=app

27th Mar 2019, 4:38 PM
ᄊム刀ノ.ᄊム乙乇ㄎイム
ᄊム刀ノ.ᄊム乙乇ㄎイム - avatar
4 Answers
+ 9
There are a couple thing wrong: First, you have to have a main() function somewhere in your code. It seems you changed it to sum, so switching it back to int main() should allow the function to run. Second, you forgot to declare the data type for the sum variable, which is why it's returning an error for that. Replacing that line with int sum = 21 + 7; should allow it to run. Lastly, in your cout statement, you seem to have put in end1 instead of endl (with a lower case L at the end instead). Swapping that out will allow it to work.
27th Mar 2019, 4:44 PM
Faisal
Faisal - avatar
+ 3
Thank you very much.❤❤❤
27th Mar 2019, 4:47 PM
ᄊム刀ノ.ᄊム乙乇ㄎイム
ᄊム刀ノ.ᄊム乙乇ㄎイム - avatar
+ 2
i got the answer. main() is a special function in c++ . Every C++ program must have a main function . Thats the problem with your program .. Copy This;;;;; #include <iostream> using namespace std; int sum (int x) { x = 21+7; return (x); } int main(){ int x; cout << sum(x); }
28th Mar 2019, 6:27 AM
Om12
Om12 - avatar
0
hel0
4th May 2019, 2:30 PM
Soledad Zinkes
Soledad Zinkes - avatar