fork download
  1. #include <iostream>
  2.  
  3.  
  4.  
  5. int
  6. main( int argc, char** argv )
  7. {
  8. float payloadInTons = 6550.3;
  9.  
  10.  
  11. // Above, payloadInTons is given a value.
  12. // Below, two different ways are used to type cast that same value,
  13. // but the results do not match.
  14. float tempVal = payloadInTons * 10.0;
  15. unsigned int right = tempVal;
  16. std::cout << " right = " << right << std::endl;
  17.  
  18.  
  19. unsigned int rawPayloadN = payloadInTons * 10.0;
  20. std::cout << " wrong = " << rawPayloadN << std::endl;
  21.  
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
    right = 65503
    wrong = 65502