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

Username:   Password: 
 RegisterRegister   
 Need help with calculating time.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mp900k7




PostPosted: Tue Feb 28, 2012 9:49 pm   Post subject: Need help with calculating time.

I need help in turing to calculate time from one to another.
my teacher asked me "Write a program that inputs the starting time and finishing time of an automobile trip as well as the distance in kilometers traveled and outputs the average speed in km/hr. The times are to be given in two parts: the hours, then the minutes."

I will be greatful if someone could give me a code to it. Rolling Eyes Question Question
Sponsor
Sponsor
Sponsor
sponsor
RandomLetters




PostPosted: Tue Feb 28, 2012 10:05 pm   Post subject: RE:Need help with calculating time.

We don't solve homework for people here, but if there is something specific that you don't understand, we'd be happy to help.

Remember that most computer science questions are really math or physics questions using computers. How would you solve this problem by hand?
Velocity




PostPosted: Wed Feb 29, 2012 12:20 am   Post subject: RE:Need help with calculating time.

do you want the user to input the times or is it one time or what? Im confused
Snario




PostPosted: Wed Feb 29, 2012 7:47 am   Post subject: Re: Need help with calculating time.

mp900k7 @ Tue Feb 28, 2012 9:49 pm wrote:
I need help in turing to calculate time from one to another.
my teacher asked me "Write a program that inputs the starting time and finishing time of an automobile trip as well as the distance in kilometers traveled and outputs the average speed in km/hr. The times are to be given in two parts: the hours, then the minutes."

I will be greatful if someone could give me a code to it. Rolling Eyes Question Question


There are lots of ways to elegantly input time as hours and minutes but considering how this is worded, it's probably expected that you create two variables (e.g., hours and minutes) that you get from the user. Next, you just have to convert that input into a workable value for time (the question specifies hours for the units). An hour is already in proper form and a minute is 1/60th of an hour. Just add them together and you have your time.

Next, just collect a value for distance (in km) and now you're set for the calculation.

Average speed is simply distance over time, both variables are in your program, just work them to produce the new value.

Spoiler:
code:
var speed, hours, minutes, distance : real
get hours, minutes, distance
speed := distance/(hours + (minutes/60))
put speed
mp900k7




PostPosted: Wed Feb 29, 2012 3:28 pm   Post subject: RE:Need help with calculating time.

ty, but i don't know how to calculate minutes and hours. lets say i started at 12:54 and ended at 18: 58, how can I find out how long i had travelled? is that more specific? because 54+58=112, and how do I make that into 52 mins and add 1+6 from the obvious 12 and 18... I will be very greatful of your help.
mp900k7




PostPosted: Wed Feb 29, 2012 3:52 pm   Post subject: Re: RE:Need help with calculating time.

Velocity @ Wed Feb 29, 2012 12:20 am wrote:
do you want the user to input the times or is it one time or what? Im confused

there are two times
start time and end time
I do not know how to calculate those, i could easily do hours but mins is hard
joshm




PostPosted: Wed Feb 29, 2012 3:59 pm   Post subject: Re: RE:Need help with calculating time.

mp900k7 @ Wed Feb 29, 2012 4:28 pm wrote:
ty, but i don't know how to calculate minutes and hours. lets say i started at 12:54 and ended at 18: 58, how can I find out how long i had travelled? is that more specific? because 54+58=112, and how do I make that into 52 mins and add 1+6 from the obvious 12 and 18... I will be very greatful of your help.


Not exactly sure what you're saying, but there are 60 minutes in an hour so 18 - 12 = 6 hours = 360 minutes and 58 minutes - 54 = 4 minutes so it would be 364 minutes. Again I am not really sure what you're asking, but I hope this helped.
ihsh




PostPosted: Wed Feb 29, 2012 4:09 pm   Post subject: Re: Need help with calculating time.

Quote:
Posted: Today at 3:28 pm Post subject: RE:Need help with calculating time.

ty, but i don't know how to calculate minutes and hours. lets say i started at 12:54 and ended at 18: 58, how can I find out how long i had travelled? is that more specific? because 54+58=112, and how do I make that into 52 mins and add 1+6 from the obvious 12 and 18... I will be very greatful of your help.


Aren't you supposed to subtract the hours from each other, and then the minutes from each other?

So suppose you start at 11:15, and finish at 12:13.

Then the total time spent would be (12-11) hours +(13-15) minutes= 1 hour - 2 minutes = (58/60) hours.
Sponsor
Sponsor
Sponsor
sponsor
copthesaint




PostPosted: Wed Feb 29, 2012 4:15 pm   Post subject: RE:Need help with calculating time.

Well simply, V = d/t,
or in your case more specifically, V = (d2-d1) / (t2-t1) which will give you velocity measured by pixels per time.
Time.ElapsedCPU will give you the approximate time in ms. since some date from 1970s
If you know how far you need to travel as well and if you have the velocity you can use that as well to get the time it takes.
mp900k7




PostPosted: Wed Feb 29, 2012 5:06 pm   Post subject: Re: Need help with calculating time.

ihsh @ Wed Feb 29, 2012 4:09 pm wrote:
Quote:
Posted: Today at 3:28 pm Post subject: RE:Need help with calculating time.

ty, but i don't know how to calculate minutes and hours. lets say i started at 12:54 and ended at 18: 58, how can I find out how long i had travelled? is that more specific? because 54+58=112, and how do I make that into 52 mins and add 1+6 from the obvious 12 and 18... I will be very greatful of your help.


Aren't you supposed to subtract the hours from each other, and then the minutes from each other?

So suppose you start at 11:15, and finish at 12:13.

Then the total time spent would be (12-11) hours +(13-15) minutes= 1 hour - 2 minutes = (58/60) hours.


okay, you are partially right. how about this timings. you start at 12:30 and end at 13:15.
I can get it to do what you said but when I was trying out other times I bumped into this. when i plug this in, the out put is 1 hour and -15 minutes.
Dreadnought




PostPosted: Wed Feb 29, 2012 6:35 pm   Post subject: Re: Need help with calculating time.

Convert either hours into minutes or minutes into hours and add the two. Your entire issue seems to be that you are keeping the two separate, but they both measure the same thing, time. In your example you either have 60 - 15 = 45 minutes or 1 - 0.25 = 0.75 hours.
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  [ 11 Posts ]
Jump to:   


Style:  
Search: