Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Calculate time
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
sockoo




PostPosted: Fri Jun 03, 2005 12:00 pm   Post subject: Calculate time

hey all .. i yet again need ur help .. i have to create a program in which tells me how much time has gone by sence midnight .. hense if the user has entered 14:25 it would output 865 minutes ..
i know how to program it but .. how would i figure out the minutes from midnight till 14:25 ? .. there's 60 minutes in an hour but .. would i times 14.25 * 60 = 855 .. so0o im 10 off .. where am i going wrong unless my teacher wrote the question wrong
Sponsor
Sponsor
Sponsor
sponsor
lyam_kaskade




PostPosted: Fri Jun 03, 2005 12:06 pm   Post subject: (No subject)

The problem is 14.25 isn't the same as 14:25
since there are 60 minutes in an hour
0.25 = 1/4 = 15 /60
so 14.25 would be 14:15, not 14:25
what you need to do is take the hours (14) times 60
and then add the minutes (25)
so, hours*60 +minutes
lyam_kaskade




PostPosted: Fri Jun 03, 2005 12:25 pm   Post subject: (No subject)

code:

var time1 : string
var min1 : int := 0
var divid, time2 : int
put "what is the time"
get time1 : *

min1 := strint (time1 (1 .. 2))*60 + strint (60 + time1 (4 .. 5))
[/code]
sockoo




PostPosted: Fri Jun 03, 2005 12:26 pm   Post subject: (No subject)

alright thanks but i'v still got a problem ...

code:

var time1 : string
var min1 : int := 0
var divid, minutes  : int
var time2, time3, time4  : real
put "what is the time"
get time1 : *
time2 := strreal (time1)
time3 := time1 (1 .. 2)
time4 := time1 (4 .. 5)
lyam_kaskade




PostPosted: Fri Jun 03, 2005 12:46 pm   Post subject: (No subject)

Hmmm...I'm not sure I follow.
The strreal won't work unless the string is made of entirely integers/decimals.
In this case it would have a colon ("14:25)" which can't be changed.
Why do you need to strreal it anyway? Do you need the time in hours or minutes?
sockoo




PostPosted: Fri Jun 03, 2005 2:53 pm   Post subject: (No subject)

it had to be in minutes .. but i just took the ez way out ..
code:

var hou, minu : int
put "what is the hour"
get hou
cls
put "what are the minutes"
get minu
cls
minutes:= hou * 60 + minu
put minutes, " minutes have passed sence midnight"


it for was for a test .. and i didnt have enough time so0 hey it works .. he never said how it had to be done Razz .. heh
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: