0

What is wrong with this c++ code? Please help

#include <iostream> using namespace std; int main() { int a, b; cout << "a is" << endl; cin >> a; cout << "b is" << endl; cin >> b; if (a > b) { cout << "greatest is " << a << endl; } if (b > a) { cout << "greatest is " << b << endl; }

17th Jun 2018, 8:37 PM
Devesh Mungad
5 Answers
+ 2
It would be much better if you would post a link to your code then we wouldnt have to copy this.
17th Jun 2018, 8:41 PM
Michael55555
Michael55555 - avatar
+ 1
怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ a return 0; is not needed, c++ will return 0 by default in main if no return statement is given
17th Jun 2018, 9:28 PM
Max
Max - avatar
+ 1
Max yes, and it's considered a mistake in C++ standard even said by the creator of the language. So some compilers will probably see it as mistake. Yet in the code there is no closing bracket for main function that will always yield an error, no matter what compiler we're on ;)
17th Jun 2018, 11:12 PM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
Jakub Stasiak i never said that there isnā€˜t a bracket missing. if the compiler doesnā€˜t compile a main function without a return statement itā€˜s not standard compliant, no matter what Bjarne Stroustrup thinks about it
17th Jun 2018, 11:15 PM
Max
Max - avatar
0
return 0 ; and please use else clause
18th Jun 2018, 4:53 PM
Aveek Bhattacharyya
Aveek Bhattacharyya - avatar