. 24-hour time (also known in the U.S. as military time) is widely used around the world. Time is expressed as hours since midnight. The day starts at 0000, and ends at 2359. • Write a program that converts am/pm time to 24-hour time. • Hints: o Think of how each hour should be handled. 12:00 am -12:59 am becomes what? 8:00 am becomes what? 12:00 pm? 1:00 pm? Group the hours into cases that should be handled similarly (e.g., 1:00 am to 11:00 am are handled the same). o Declare variables for hoursAmPm, minAmPm, and hours24. Note that minutes for 24-hour time remain the same as for am/pm, so no extra variable is needed. o Use an if-else statement to detect each case, and set the hours24 appropriately. o When outputting hour24, check if the hour is 0-9 (just check for < 10). If so, output a "0". So 7 will be output as 07. Do the same when outputting the minutes.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter1: Fundamentals Of C++ Programming
Section1.3: Preliminary Three: Software Development
Problem 7E: (Statistics) This is the formula for the standard normal deviate, z, used in statistical...
icon
Related questions
Question
100%

Trying to write a program in C++ that converts 12 hour time to 24 hour time. Thanks!

. 24-hour time (also known in the U.S. as military time) is widely used
around the world. Time is expressed as hours since midnight. The day
starts at 0000, and ends at 2359.
• Write a program that converts am/pm time to 24-hour time.
• Hints:
o Think of how each hour should be handled. 12:00 am -12:59 am
becomes what? 8:00 am becomes what? 12:00 pm? 1:00 pm?
Group the hours into cases that should be handled similarly (e.g.,
1:00 am to 11:00 am are handled the same).
o Declare variables for hoursAmPm, minAmPm, and hours24. Note
that minutes for 24-hour time remain the same as for am/pm, so no
extra variable is needed.
o Use an if-else statement to detect each case, and set the hours24
appropriately.
o When outputting hour24, check if the hour is 0-9 (just check for <
10). If so, output a "0". So 7 will be output as 07. Do the same when
outputting the minutes.
Transcribed Image Text:. 24-hour time (also known in the U.S. as military time) is widely used around the world. Time is expressed as hours since midnight. The day starts at 0000, and ends at 2359. • Write a program that converts am/pm time to 24-hour time. • Hints: o Think of how each hour should be handled. 12:00 am -12:59 am becomes what? 8:00 am becomes what? 12:00 pm? 1:00 pm? Group the hours into cases that should be handled similarly (e.g., 1:00 am to 11:00 am are handled the same). o Declare variables for hoursAmPm, minAmPm, and hours24. Note that minutes for 24-hour time remain the same as for am/pm, so no extra variable is needed. o Use an if-else statement to detect each case, and set the hours24 appropriately. o When outputting hour24, check if the hour is 0-9 (just check for < 10). If so, output a "0". So 7 will be output as 07. Do the same when outputting the minutes.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 7 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning