aboutsummaryrefslogtreecommitdiff
path: root/CST116F2021-Lab4/CST116F2021-Lab4.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'CST116F2021-Lab4/CST116F2021-Lab4.cpp')
-rw-r--r--CST116F2021-Lab4/CST116F2021-Lab4.cpp31
1 files 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