diff options
author | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
---|---|---|
committer | msglm <msglm@techchud.xyz> | 2023-01-14 05:31:48 -0600 |
commit | 9d53d8857eaa1c9405894a88ca75bc4657e42f35 (patch) | |
tree | eb1efc1d028b949dd83bb710c68be8eff58f26e7 /C++/Ch6Practice1/Ch6Practice1.cpp | |
download | school-code-master.tar.gz school-code-master.tar.bz2 school-code-master.zip |
Diffstat (limited to 'C++/Ch6Practice1/Ch6Practice1.cpp')
-rw-r--r-- | C++/Ch6Practice1/Ch6Practice1.cpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/C++/Ch6Practice1/Ch6Practice1.cpp b/C++/Ch6Practice1/Ch6Practice1.cpp new file mode 100644 index 0000000..4623714 --- /dev/null +++ b/C++/Ch6Practice1/Ch6Practice1.cpp @@ -0,0 +1,97 @@ +// Name: msglm +// Date: +// Program Name: +// Description: + + +#include <iostream> +#include <string> +#include <iomanip> +using namespace std; + +//Function header (probably should be in a header file) +int civi_to_mili(int startTime, string meridian); +int mili_to_civi(int startTime, string &meridian); + +// Named constants + +int main() { + + //Variable declaration + int hour; + int minute; + int choice; + string meridian; + int trueHour; + //Program title and description for the user + cout << "Title: Military-To-Civilian time converter" << endl << "Description: converts military to civilian time and vice-versa" << endl; + do { + + // User input + cout << "Enter the hour" << endl; + cin >> hour; + + cout << "Enter the minute" << endl; + cin >> minute; + trueHour = hour; + + cout << "AM or PM? (either works if military time)" << endl; + cin >> meridian; + + if (!cin) { + cin.clear(); + cin.ignore(100, '\n'); + } + + } while (!cin); + + do { + cout << "1. Convert Civi to Mili\n"; + cout << "2. Convert Mili to Civi\n"; + cout << "3. Print current time\n"; + cout << "4. Exit\n"; + cout << "Choice: \n"; + cin >> choice; + if (choice == 1) { + trueHour = civi_to_mili(trueHour, meridian); + cout << "\033[2J\033[1;1H"; + cout << "time: \n"; + cout << trueHour << ":" << minute << " " << meridian << endl; + } else if (choice == 2) { + trueHour = mili_to_civi(trueHour, meridian); + cout << "\033[2J\033[1;1H"; + cout << "time: \n"; + cout << trueHour << ":" << minute << " " << meridian << endl; + } else if (choice == 3) { + cout << "\033[2J\033[1;1H"; + cout << "time: \n"; + cout << trueHour << ":" << minute << " " << meridian << endl; + } else { + return 0; + } + } while (cin); +} + +int civi_to_mili(int startTime, string meridian) { + if (meridian == "PM"){ + return startTime + 12; + } else { + return startTime; + } +} +int mili_to_civi(int startTime, string &meridian) { + if (startTime > 12){ + meridian = "PM"; + return startTime-12; + } else { + meridian = "AM"; + return startTime; + } +} + +/*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + |