Convert time-24 hour to 12 hour

Source: Internet
Author: User

Convert time-24-hour conversion to 12-hour conversion, allows repeated calculation:

// Convert time # include <iostream> using namespace STD; void get_time (Int & hours, Int & minutes); void convert_time (Int & hours, char & ampm ); void show_time (INT hours, int minutes, char ampm); int main () {int hours, minutes; char ans, ampm; do {get_time (hours, minutes ); convert_time (hours, ampm); show_time (hours, minutes, ampm); cout <"do you want again? "; CIN> ans;} while ('y' = ans | 'y' = ans);} void get_time (Int & hours, Int & minutes) {char B; cout <"Enter the time like 11: 11 format: \ n"; CIN> hours> B> minutes;} void convert_time (Int & hours, char & A) {If (hours <12) A = 'a'; else if (hours> 12) {hours-= 12; A = 'P ';} else if (hours = 12) {A = 'P' ;}} void show_time (INT hours, int minutes, char ampm) {cout <"the convert time is" 

Result:

 
Enter the time like 11: 11 format: 11: 30the convert time is 11: 30 Amdo you want again? Yenter the time like format: 15: 30the convert time is pmdo you want again? Yenter the time like format: 12: 30the convert time is pmdo you want again? Yenter the time like 11: 11 format: 0: 40The convert time is 0: 40 Amdo you want again?


Convert time-24 hour to 12 hour

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.