title: C++ convert decimal hours into hours, minutes, and seconds
body: <p>I have some number of miles and a speed in MPH that I have converted into the number of hours it takes to travel that distance at that speed. Now I need to convert this decimal number into hours, minutes, and seconds. How do I do this? My best guess right now is:</p>
  
  <pre><code>double time = distance / speed;
  int hours = time; // double to integer conversion chops off decimal
  int minutes = (time - hours) * 60;
  int seconds = (((time - hours) * 60) - minutes) * 60;
  </code></pre>
  
  <p>Is this right? Is there a better way to do this? Thanks!</p>