C++ The code has to fit in the /* Type your code here. */ section. Nothing above or below that can be changed in any way. It does not let me click anywhere but there. 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. If the input is 2:30 pm, the output should be
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
C++ The code has to fit in the /* Type your code here. */ section. Nothing above or below that can be changed in any way. It does not let me click anywhere but there.
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. If the input is 2:30 pm, the output should be 1430. If the input is 12:01 am, the output should be 0001.
Hints:
-
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).
-
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.
-
Use an if-else statement to detect each case, and set the hours24 appropriately.
-
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
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images