+ 1
Why doesn't this work?
I've been trying to make a program where you input 3 numbers and it outputs the biggest number or in the case of several biggest numbers, one of them. But I can't figure out why it's not working properly. I narrowed it down to this part of it not working properly: int main() { int a, b, c; cin >> a >> b >> c; if (b > a && c) { cout << b; } return 0; } If I type in 1 2 3, it outputs 2. I just can't wrap my head around such a simple problem.
8 ответов
+ 16
Current program flow.
a = 1
b = 2
c = 3
if (2 > 1 && 3)
if (true && true)
if (true)
cout << 2;
+ 15
@Mr.e
If you had any question about my solution feel free and ask.
+ 14
Here is your solution. One-liner guy!
cout << (a > b && a > c ? a : (b > a && b > c ? b : c));
+ 5
Try this
int main() {
int a,b,c;
if(a>b&&b>c){
cout<<a;
}
else if(b>a&&a>c){
cout<<b;
}
else {
cout<<c;
}
return 0;
}
+ 4
According to your code it will always print b bcos c is true.
instead say, if( b>a & b>c)
+ 2
@jhk123 Thank you, this was extremely confusing with the ton of different answers, but you saved me.
0
@Dev
I literally copy and pasted your code and it STILL shows 2.