+ 3
Who can say what's wrong with this code?(C++)
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.
+ 3
Thank you very much.❤❤❤
+ 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);
}
0
hel0