46.7k views
0 votes
Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations and to quit the program. Furthermore, your program must contain at least the following functions:

a) A function to convert the time from 24-hour notation to 12-hour notation and returns the new time.
b) A function to convert the time from 12-hour notation to 24-hour notation and returns the new time.
c) A function to display the choices.
d) Function(s) to get the input values and returns them.
e) Function(s) to display the results. For 12-hour time notation, your program must display am or pm. For both times, the program must display each of hours, minutes, and seconds in two digits.
f) Main function that calls all other functions and allows the user to select from the menu more than one time. Do not use global variables.

1 Answer

2 votes

Final answer:

A program to convert between 24-hour and 12-hour time notations requires functions for conversion, input, output, and menu display. The main function operates a loop for the user to repeatedly choose conversion options or to quit. Each conversion accounts for formatting and the addition of 'am' or 'pm' when necessary.

Step-by-step explanation:

Program to Convert Between 24-hour and 12-hour Time Notation

To write a program that converts between 24-hour and 12-hour time notation, we need to define several functions to handle the conversion, user input, and menu display. The functions are:

  • A function to convert time from 24-hour notation to 12-hour notation (with 'am' or 'pm') and return the new time.
  • A function to convert time from 12-hour notation to 24-hour notation and return the new time.
  • A function to display the choices to the user.
  • Functions to get the user input values and return them.
  • Functions to display the results with each of hours, minutes, and seconds in two digits.
  • The main function that calls all other functions and operates the menu loop.

The main function will continuously display the menu and prompt the user to choose an option to convert time, either from 24-hour to 12-hour or vice versa, and an option to quit the program.

User Jose Angel Maneiro
by
8.5k points