We have an issue that I have been able to recreate with this sample code:
int main()
{
double d = -2;
// ...
cout << "d: " << d << endl;
cout << "-d: " << -d << endl;
cout << "Conditional Operator (expect value 2): " << (d < 0)? -d : d;
cout << endl;
return 0;
}
The output is as follows:
d: -2
-d: 2
Conditional Operator (expect value 2): 1
>Solution :
It’s a problem of operator precedence. Use:
cout << "Conditional Operator (expect value 2): " << (d < 0? -d : d);