So essentially I'm completely lost with this problem our professor gave us. I was absent for the lecture, and he isn't very keen on uploading the lecture notes before our assignments are due. Anyway, the program to be written goes something like this.

We need to write a non-graphical program that gets a time in hours, minutes and the am/pm from a user, and have it calculate how many minutes frmo midnight that specific time is. The format the times should be entered in is hh:mmx where x can equal a or p for AM or PM respectively.

So, if we decide to enter 01:00p, the program should calculate 13x60=780 minutes that have passed since midnight. Honestly I'm stumped. I understand the concept, but can't for the life of me figure out how to put it into code. Any help or explanation would be extremely appreciated! Thank you.

Recommended Answers

All 2 Replies

Well i don't want to do your homework for you, but it's pretty straight forward.

You can make a function, and pass it the time in hh:mmx format.
Then do the calculations you need.
And return the value you got.

Pass it to the function as a string, then use index slicing to put the parts you need to do the calculations on in their own variables and convert them to int.

Divide the problem into smaller problems
1. Find out how to take input from a user.
2. Validate the input is in correct format.
3. Find out the input is am or pm.
4. Convert the time to 24 hour block and get rid of pm and am.
5. Split rest of the input at the colon into two numbers.
6. Multiply the first part by 60 to convert to minutes.
7. Add the result from 6 to the second number.

Then tell me what step you are stuck at?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.