Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » convert seconds to hrs and mins
Closed Thread
Old 01-27-2005, 09:34 PM   #1 (permalink)
ibexpiotr's Avatar
 
True Techie

Join Date: Nov 2003

Posts: 197

ibexpiotr is on a distinguished road

Send a message via AIM to ibexpiotr
Default convert seconds to hrs and mins

C++
can anyone write me a code that converts seconds to hrs and minutes.
THX
ibexpiotr is offline  
Old 01-28-2005, 02:34 AM   #2 (permalink)
 
Monster Techie

Join Date: May 2004

Location: /usr/root/mn/us

Posts: 1,121

bla!! is on a distinguished road

Default

Reeks of someone not wanting to do their homework.

Think about the basics.

Take input from the user
Do a quick calcuation (X/3600) to convert to hours or (x/60) to convert to minutes
Print out the new value
__________________
<br>
Its a frigging Laptop, not a Labtop!!!!
bla!! is offline  
Old 01-28-2005, 07:52 AM   #3 (permalink)
ibexpiotr's Avatar
 
True Techie

Join Date: Nov 2003

Posts: 197

ibexpiotr is on a distinguished road

Send a message via AIM to ibexpiotr
Default

u dont understand..
heres an expample. u got 7300seconds(2hrs and 10mins- if im not mistaken)

and the output should look like this . 2rhs and 10mins. i know that i need to extract the remainder somehow,,

pls help
ibexpiotr is offline  
Old 01-28-2005, 11:34 AM   #4 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

you use the modulo operator %.
Convert it to minutes first, then use the modulo operator to convert to hours and minutes:
Code:
int seconds = 7300;
int minutes = 0;
int hours = 0;

// start calculation
minutes = seconds/60;
hours = minutes/60;
minutes = minutes%60;
I'm getting 2hr 1min btw. Then you just use a printf() to print the values.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
Old 01-28-2005, 04:39 PM   #5 (permalink)
 
Super Techie

Join Date: Jan 2005

Posts: 295

gab00n

Default

You forgot the s, it is modulos operator. It is just simple maths, just play around next time to figure it out by yourself. Yuo won't learn anything if eveybody else has to solve it for you.
__________________
\"Today\'s scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.\" Nikola Tesla
gab00n is offline  
Old 01-29-2005, 04:46 PM   #6 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

My bad Thanks for the correction.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On