aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CST116F2021-Lab4/CST116F2021-Lab4.cpp80
1 files changed, 50 insertions, 30 deletions
diff --git a/CST116F2021-Lab4/CST116F2021-Lab4.cpp b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
index 451500b..d56d919 100644
--- a/CST116F2021-Lab4/CST116F2021-Lab4.cpp
+++ b/CST116F2021-Lab4/CST116F2021-Lab4.cpp
@@ -6,18 +6,18 @@
using namespace std;
-void GetInput(int& hours, int& minutes, int& seconds);
-void DisplayTime(int& hours_display, int& minutes_display, int& seconds_display);
+void GetInput(int& display_input, int& hours, int& minutes, int& seconds);
+void DisplayTime(int display_display,int& hours_display, int& minutes_display, int& seconds_display);
int main()
{
- int hours = 0, minutes = 0, seconds = 0;
- GetInput(hours, minutes, seconds);
+ int display = 1, hours = 0, minutes = 0, seconds = 0;
+ GetInput(display, hours, minutes, seconds);
- DisplayTime(hours, minutes, seconds);
+ DisplayTime(display, hours, minutes, seconds);
}
-void GetInput(int& hours_input, int& minutes_input, int& seconds_input)
+void GetInput(int& display_input, int& hours_input, int& minutes_input, int& seconds_input)
{
do
{
@@ -36,40 +36,60 @@ void GetInput(int& hours_input, int& minutes_input, int& seconds_input)
cout << "Please enter the current seconds from 0 to 59: ";
cin >> seconds_input;
} while (seconds_input < 0 || seconds_input > 59);
+
+ do
+ {
+ cout << "Please choose the display format by entering the corresponding number.\n1. Standard Time\n2. Military Time\n3. 24-hour Notation\n";
+ cin >> display_input;
+ } while (display_input < 1 || display_input > 3);
}
-void DisplayTime(int& hours_display, int& minutes_display, int& seconds_display)
+void DisplayTime(int display_display, 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) //fix for PM time
+ switch (display_display)
{
- hours_display -= 12;
- suffix = " P.M.";
- }
- else if (hours_display == 12) //fix for 12 noon
- suffix = " P.M.";
- else if (hours_display == 0) //fix for 12 midnight
+ case 1:
{
- hours_display += 12;
- suffix = " A.M.";
+ //set hours to 12 hours time before cout
+ string suffix;
+
+ if (hours_display > 12 && hours_display != 0) //fix for PM time
+ {
+ hours_display -= 12;
+ suffix = " P.M.";
+ }
+ else if (hours_display == 12) //fix for 12 noon
+ suffix = " P.M.";
+ else if (hours_display == 0) //fix for 12 midnight
+ {
+ hours_display += 12;
+ suffix = " A.M.";
+ }
+ 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;
+ break;
}
- 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;
- //Revert back to 24 hour format
+ case 2:
+ {
+ //OUTDATED::::IGNORE
+ //Revert back to 24 hour format
- if (suffix == " A.M." && hours_display == 12) //fix for midnight
- hours_display = 0;
- else if (suffix == " P.M.") //fix for PM times
- hours_display += 12;
+ //if (suffix == " A.M." && hours_display == 12) //fix for midnight
+ // hours_display = 0;
+ //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 24 hour notation 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;
+ break;
+ }
+ case 3:
+ 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;
+ break;
+ }
}
//p.214