That is because how you are using the ?: operator in the cout. It's all about
precedence of operators[
^]. Bracket being one of the top most.
When you write:
cout << (d > c) ? d : c;
d>c is evaluated as they are in brackets and the result of that is printed. So the values would be 0 or 1 always and none of the a,b,c values there.
A small change should work:
#include<iostream>
using namespace std;
int main()
{
int a, b, c, d;
cout << "Enter three numbers.";
cin >> a >> b >> c;
d = ( a>b ? a : b );
cout << (d > c ? d : c);
return 0;
}
Moved the entire
?:
inside the
bracket
which is intended.