saiz66 Posted June 14, 2004 Share Posted June 14, 2004 Hi. How do I convert minutes into standard time, for example 720 min into 12:00. Thanks! :ninja: Link to comment Share on other sites More sharing options...
0 John Veteran Posted June 14, 2004 Veteran Share Posted June 14, 2004 Divide by 60, there's a start :p int mins = 720; int hours = mins / 60; int minutes = mins % 60; cout << hours << ":" << minutes << endl; Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted June 14, 2004 Share Posted June 14, 2004 Divide by 60? Link to comment Share on other sites More sharing options...
0 insurektion Posted June 14, 2004 Share Posted June 14, 2004 /60 take remainder (decimal * 100 /60) - remainder Link to comment Share on other sites More sharing options...
0 Erekigitaa Posted June 14, 2004 Share Posted June 14, 2004 I would devide by 60, set the result as your hour and the remainder as your minutes. Make sure to use doubles, or devide by 60.0. If you use double, you need to typecast your hour as (int). Otherwise, you'll get something like 2.0 hours. Then just use a simple print statement (if u want to print) to output ur quotient and remainder separated by the a colon ":" Hope this helps. EDIT For the remainder just use the modulus operator % There's no need for decimal remainders or what not. Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted June 14, 2004 Share Posted June 14, 2004 (edited) cout << hour/60 << ":" << hour%60; Edited June 14, 2004 by kjordan2001 Link to comment Share on other sites More sharing options...
0 John Veteran Posted June 14, 2004 Veteran Share Posted June 14, 2004 cout << hour/60.0 << ":" << hour%60.0 That won't work because you're using doubles. You can't use mod with doubles :p And if you divide by a double, then it will evaluate to a double, which he doesn't want. You'd have to do this: cout << hour / 60 << ":" << hour % 60; Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted June 14, 2004 Share Posted June 14, 2004 (edited) Whoops, not sure why I stuck .0 on there :wacko: Guess I saw the .0's in the post before that and my mind somehow stuck them on. I mean...errr...I don't know what you're talking about :whistle: Edited June 14, 2004 by kjordan2001 Link to comment Share on other sites More sharing options...
0 saiz66 Posted June 14, 2004 Author Share Posted June 14, 2004 so this will work with any minutes? for example high numbers such as 45000 min? Link to comment Share on other sites More sharing options...
0 John Veteran Posted June 14, 2004 Veteran Share Posted June 14, 2004 Try it and find out (Y) Link to comment Share on other sites More sharing options...
0 saiz66 Posted June 14, 2004 Author Share Posted June 14, 2004 (edited) hi. I tried the hours = theTime / 60; minutes = theTime % 60; cout << hours << ":" << minutes << endl; for 1149 mins it shows the standard time as 19:9.. how do I make this 7:09 instead? Edited June 14, 2004 by saiz66 Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted June 14, 2004 Share Posted June 14, 2004 cout.width(2); cout.fill('0'); or cout.precision(2); may work too. Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted June 14, 2004 Share Posted June 14, 2004 hi. I tried the hours = theTime / 60; minutes = theTime % 60; cout << hours << ":" << minutes << endl; It works good except I get 12:0, is there a way to make it 12:00? cout << (mins < 10 ? "0" : "") << mins << endl; Subtract 12 if the hour is greater than 12. Link to comment Share on other sites More sharing options...
0 saiz66 Posted June 14, 2004 Author Share Posted June 14, 2004 thanks for all the help guys but I edited my last post. "for 1149 mins it shows the standard time as 19:9.. how do I make this 7:09 instead? " Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted June 14, 2004 Share Posted June 14, 2004 thanks for all the help guys but I edited my last post. "for 1149 mins it shows the standard time as 19:9.. how do I make this 7:09 instead? " See the last 2 posts, either should work. :whistle: Link to comment Share on other sites More sharing options...
0 saiz66 Posted June 14, 2004 Author Share Posted June 14, 2004 sorry didnt see it! thanks to all for the generous help! Link to comment Share on other sites More sharing options...
Question
saiz66
Hi. How do I convert minutes into standard time, for example 720 min into 12:00. Thanks!
:ninja:
Link to comment
Share on other sites
15 answers to this question
Recommended Posts