- #1
sid_galt
- 502
- 1
My VC++ Express compiler has been acting very funnily of late.
I tried the following code
The problem with this was that the program was now converting all the sum values generated into 1.0, even those which were greater than 1.0.
Instead of using the if statement, I tried the conditional operator and then it worked fine.
Does anyone know the reason for this discrepancy?
I tried the following code
Code:
for(whatever)
{
double sum = whatever;
if(sum > 5.0)
sum = 5
else if(sum < 1.0)
sum = 1
}
The problem with this was that the program was now converting all the sum values generated into 1.0, even those which were greater than 1.0.
Instead of using the if statement, I tried the conditional operator and then it worked fine.
Code:
for(whatever)
{
double sum = whatever;
sum = sum > 5? 5:sum;
sum = sum < 1? 1:sum;
}//Working Okay
Does anyone know the reason for this discrepancy?