The Microwave Problem

Difficulty: Medium


I have a smart microwave oven. Say I need to heat my tea for a minute and a half. I type in 90. When I press the Start button, the 90 transforms into 1:30, a minute thirty. It’s the same quantity of time, but expressed differently. Such magic is merely clever programming.

Your task for this month’s Exercise is to write the input routine for a microwave oven. It accepts a given number of seconds, specified as an int value. The code digests this number, then outputs the accurate number of hours, minutes, and seconds.

Here is a sample run of my solution:

Enter time in seconds: 90
That's 0:01:30

And another:

Enter time in seconds: 4000
That's 1:06:40

And yet another:

Enter time in seconds: 604831
That's 168:00:31

As a hint, especially if you’re new to planet Earth: Remember that a minute consists of 60 seconds and an hour consists of 60 minutes or 3600 seconds.

Click here to view my solution. Incidentally, my solution uses no decision keywords, only math.

Leave a Reply