+ 1
What's wrong with my code. Why it doesn't work? I can't understand
5 ответов
+ 18
/*logical error got caught ::: a>b and b<a are the same .... U must write b>a in place of b<a*/
//corrected code
#include <iostream>
using namespace std;
int main() {
int a,b;
cout << "Put two numbers \n";
cin >> a >> b;
cout << a << endl << b << endl;
if (a>b) {
cout << "Greatest is a";
}
else if (b>a){
cout << "Greatest is b";
}
else if (a==b){
cout << "a and b are equal";
}
return 0;
}
+ 17
@Poorie
//sometimes these errors occurs 😅
//I too have done and It is hard to catch such errors when lines in codes are large ... as they don't show what is the error at runtime , so we must view code again(or check each part by enclosing other in comments) .
+ 2
a>b is same with b<a
+ 1
Thank you for your answers guys! I can't believe, that i've done such a stupid fail.
+ 1
Gaurav Agrawal
That's true. Such a guileful trap!