By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,797 Members | 1,848 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,797 IT Pros & Developers. It's quick & easy.

Guidelines on how to write a C Program that will calculate time in hours and minutes

P: 1
Hi,

I am Patricia and I would like to get some assistance to write a Program in C.
Your help would be greatly appreciated.

The Program must calculate how long it takes to fly from one place to another if the program is given:
a. starting place
b. departure time in hours and minutes
c. destination
d. arrival time in hours and minutes
e. the time difference in hours between starting place and destination.

Note: Departure and arrival are on the same day.
The answer should be in hours and minutes and only integer arithmetic is allowed.
Jun 12 '07 #1
Share this Question
Share on Google+
4 Replies


DeMan
100+
P: 1,806
Hi patsandy,

Welcome to thescripts. I will move this thread to the C Forum, where better qualified experts can have a look at it. You will still be able to access it from this thread, however to post directly to hte c forum in future, select it from the options available from the blue bar near the top of the screen.

I hope the experts in the c/c++ forum can be of help!
Jun 12 '07 #2

Savage
Expert 100+
P: 1,764
Hi,

I am Patricia and I would like to get some assistance to write a Program in C.
Your help would be greatly appreciated.

The Program must calculate how long it takes to fly from one place to another if the program is given:
a. starting place
b. departure time in hours and minutes
c. destination
d. arrival time in hours and minutes
e. the time difference in hours between starting place and destination.

Note: Departure and arrival are on the same day.
The answer should be in hours and minutes and only integer arithmetic is allowed.
Hi Patricia,
welcome and thank you for joining the scripts.Please ask a specific question so that we can help you and also it's highly recommended that you read pstong guidelines

Savage
Jun 12 '07 #3

P: 23
Hi Patricia,

Just to give you some initial hints (though you can do it in so many ways!!):

1) Check if both times are in 24 hour clock or not. If yes then its fine, otherwise turn them into 24 hour clock system (you just need to add 12 if the given time is in pm).

2) It will be easier for further calculation if you transfer those times into decimal system. All you need to do is : given hour + (given min/60)

3) Now you are almost done! Just find a way to subtract those times and use time difference in your calculation :D I am sure you can find that out.

Hope it helps

--Sorower
Jun 12 '07 #4

100+
P: 208
Hi,

I am Patricia and I would like to get some assistance to write a Program in C.
Your help would be greatly appreciated.

The Program must calculate how long it takes to fly from one place to another if the program is given:
a. starting place
b. departure time in hours and minutes
c. destination
d. arrival time in hours and minutes
e. the time difference in hours between starting place and destination.

Note: Departure and arrival are on the same day.
The answer should be in hours and minutes and only integer arithmetic is allowed.
1. Convert b, d into the same measurement of time (if they're different, ie one 12hr one 24hr)
2. Subtract b from d
3. Add e to the answer from 2.

PS. Didn't read through the post above :P Sorry for basically the same answer
Jun 12 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.