From f6f5af1f3006583d389be576f51061a71a002976 Mon Sep 17 00:00:00 2001 From: WiserJ Date: Tue, 26 Oct 2021 15:10:25 -0700 Subject: military --- CST116F2021-Lab4/CST116F2021-Lab4.cpp | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index 3cd63cc..ebae03f 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -21,21 +21,21 @@ void GetInput(int& hours_input, int& minutes_input, int& seconds_input) { do { - cout << "Please enter the current hour out of 24 per day: "; + cout << "Please enter the current hour from 0 to 23: "; cin >> hours_input; - } while (hours_input <= 0 || hours_input > 24); + } while (hours_input < 0 || hours_input > 23); do { - cout << "Please enter the current minutes out of 60 per hour: "; + cout << "Please enter the current minutes from 0 to 59: "; cin >> minutes_input; - } while (minutes_input < 0 || minutes_input > 60); + } while (minutes_input < 0 || minutes_input > 59); do { - cout << "Please enter the current seconds out of 60 per minute: "; + cout << "Please enter the current seconds from 0 to 59: "; cin >> seconds_input; - } while (seconds_input < 0 || seconds_input > 60); + } while (seconds_input < 0 || seconds_input > 59); } void DisplayTime(int& hours_display, int& minutes_display, int& seconds_display) @@ -43,20 +43,29 @@ void DisplayTime(int& hours_display, int& minutes_display, int& seconds_display) //set hours to 12 hours time before cout string suffix; - if (hours_display > 12) + if (hours_display > 12 && hours_display != 0) { hours_display -= 12; suffix = " P.M."; } - else + else if (hours_display == 12) + suffix = " P.M."; + else if (hours_display == 0) { + hours_display += 12; suffix = " A.M."; } + else + suffix = " A.M."; + + cout << "\nThe current time in standard time is " << hours_display << ":" << setw(2) << setfill('0') << minutes_display << ":" << setw(2) << setfill('0') << seconds_display << suffix; + if (suffix == " A.M." && hours_display == 12) + hours_display = 0; + else if (suffix == " P.M.") + hours_display += 12; - cout << "The current time in standard time is " << hours_display << ":" << setw(2) << setfill('0') << minutes_display << ":" << setw(2) << setfill('0') << seconds_display << suffix; - - + cout << "\nThe current time in military time is " << setw(2) << setfill('0') << hours_display << setw(2) << setfill('0') << minutes_display << ":" << setw(2) << setfill('0') << seconds_display; } //p.214 -- cgit v1.2.3