aboutsummaryrefslogtreecommitdiff
path: root/7c/9.5/9.5.cpp
diff options
context:
space:
mode:
Diffstat (limited to '7c/9.5/9.5.cpp')
-rw-r--r--7c/9.5/9.5.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/7c/9.5/9.5.cpp b/7c/9.5/9.5.cpp
new file mode 100644
index 0000000..b04a686
--- /dev/null
+++ b/7c/9.5/9.5.cpp
@@ -0,0 +1,58 @@
+// 9.5.cpp : This file contains the 'main' function. Program execution begins and ends there.
+//
+
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+void GetInput(int& hrs, int& min, int& sec);
+void Output(int hrs, int min, int sec, int format=0);
+
+int main()
+{
+ int hrs, min, sec;
+ GetInput(hrs, min, sec);
+ Output(hrs, min, sec);
+ Output(hrs, min, sec, 1);
+ Output(hrs, min, sec, 2);
+}
+
+
+void GetInput(int& hrs, int& min, int& sec)
+{
+ cout << "Input the hour in 24 hour time: ";
+ cin >> hrs;
+
+ cout << "\nInput the minute: ";
+ cin >> min;
+
+ cout << "\nInput the second: ";
+ cin >> sec;
+
+ cout << "\n\n";
+}
+
+void Output(int hrs, int min, int sec, int format)
+{
+ if (format == 2)
+ {
+ cout << "Showing in 24-hour time:\n";
+ cout << setw(2) << setfill('0') << hrs << ":" << setw(2) << min << ":" << setw(2) << sec << "\n";
+ }
+ else if (format == 1)
+ {
+ cout << "Showing in military time:\n";
+ cout << setw(2) << setfill('0') << hrs << setw(2) << min << ":" << setw(2) << sec << "\n";
+ }
+ else
+ {
+ cout << "Showing in regular time:\n";
+ if (hrs >= 12) {
+ cout << hrs-12 << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << sec << " PM" << "\n";
+ }
+ else
+ {
+ cout << hrs << ":" << setw(2) << setfill('0') << min << ":" << setw(2) << sec << " AM" << "\n";
+ }
+ }
+} \ No newline at end of file