From 496c4fb20b473637d5127d5e66d825b88c4981f9 Mon Sep 17 00:00:00 2001 From: WiserJ Date: Tue, 26 Oct 2021 15:37:10 -0700 Subject: maybe finished --- CST116F2021-Lab4/CST116F2021-Lab4.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp index 8973760..451500b 100644 --- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp +++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp @@ -43,31 +43,33 @@ 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 && hours_display != 0) + if (hours_display > 12 && hours_display != 0) //fix for PM time { hours_display -= 12; suffix = " P.M."; } - else if (hours_display == 12) + else if (hours_display == 12) //fix for 12 noon suffix = " P.M."; - else if (hours_display == 0) + else if (hours_display == 0) //fix for 12 midnight { hours_display += 12; suffix = " A.M."; } - else + else //remaining times are AM 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) + //Revert back to 24 hour format + + if (suffix == " A.M." && hours_display == 12) //fix for midnight hours_display = 0; - else if (suffix == " P.M.") + else if (suffix == " P.M.") //fix for PM times hours_display += 12; 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; - 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; + cout << "\nThe current time in 24 hour notation 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