Project 5

due at midnight on   +60

This assignment will help you practice using nested conditional and switch statements. Call your program p5time.cpp and submit to this dropbox for project 5.

Write a program that will:

  1. Ask the user for an hour (input as an integer 0–23).
  2. Ask the user for a minute (input as an integer 0–59).
  3. Give an error message and stop if either integer is outside the required range.
  4. Print the 24-hour time along with the equivalent 12-hour (AM/PM) time. The times should include leading zeros as necessary, so that it prints 03:08 rather than 3:8 for 3:08 AM.
  5. Print an English description of the time, rounded to the nearest quarter-hour, and specifying morning, afternoon, or evening. (See the examples below.)

Again, to receive full credit:

  • Make sure you use appropriate indentation and alignment of braces.
  • Include a comment at the top with your name and the date.
  • Try to remove unnecessary repetition from your program.

Here are some sample runs of my solution, but it should work for other numbers as well.

Enter hour (0-23): 11
Enter minute (0-59): 15
11:15 is 11:15 AM
quarter past eleven in the morning
Enter hour (0-23): 17
Enter minute (0-59): 58
17:58 is 5:58 PM
six in the evening
Enter hour (0-23): 13
Enter minute (0-59): 21
13:21 is 1:21 PM
quarter past one in the afternoon
Enter hour (0-23): 13
Enter minute (0-59): 28
13:28 is 1:28 PM
half past one in the afternoon

Times around 45 minutes past the hour should, in English, refer to the subsequent hour:

Enter hour (0-23): 19
Enter minute (0-59): 48
19:48 is 7:48 PM
quarter til eight in the evening

When the hour is 12 or 0, it should refer to noon or midnight:

Enter hour (0-23): 12
Enter minute (0-59): 3
12:03 is 12:03 PM
noon
Enter hour (0-23): 0
Enter minute (0-59): 20
00:20 is 12:20 AM
quarter past midnight

But watch out when it’s close to 45 minutes after noon or midnight:

Enter hour (0-23): 12
Enter minute (0-59): 40
12:40 is 12:40 PM
quarter til one in the afternoon
Enter hour (0-23): 0
Enter minute (0-59): 40
00:40 is 12:40 AM
quarter til one in the morning

And don’t forget the error-checking:

Enter hour (0-23): -5
Error: hour out of range.
Enter hour (0-23): 24
Error: hour out of range.
Enter hour (0-23): 5
Enter minute (0-59): 70
Error: minute out of range.