i need help i can't find the awnser , sorry if this is newbie question im new
#include using namespace std;
int main ()
{
int a, b, c;
int result;
a = 5;
b = 2;
c = 3;
a = a + 4;
result = a - b + c;
cout << result;
cin.get();
}
Three answers:
Cubbi
2011-07-12 06:37:59 UTC
There are NO ERRORS in your code, is it fully compliant with every revision of C++.
Contrary to one answer you received, main() does not need a return statement even though it has a non-void return type. It's just one of the many ways in which main is different from user-declared functions. It's true though that some compilers erroneously warn about this -- in such cases "return 0;" may be needed.
The program can be improved stylistically by declaring variables when they are needed, rather than at the beginning of main(), as in "int result = a - b + c;", but there are no actual errors to fix.
Anand N
2011-07-12 08:47:12 UTC
You are missing a return statement , try this code instead
#include
using namespace std;
int main ()
{
int a, b, c;
int result;
a = 5;
b = 2;
c = 3;
a = a + 4;
result = a - b + c;
cout << result;
cin.get();
return 0;
}
Sujit Jha
2011-07-12 10:05:15 UTC
Your Code is correct. When you compile this code it give a warning "Function Main should return a value" because you given main as int return type.But this is not an error you can execute it using CTRL+F9.
You need to change main as void main() for remove the warning message.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.