Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main (){
- char choice, input;
- string timeType;
- int time;
- cout << "Format A: 12-hour to 24-hour" << endl;
- cout << endl;
- cout << "Format B: 24-hour to 12-hour" << endl;
- cout << endl;
- cout << "Enter the lowercase letter of the format you wish to use: ";
- cin >> choice;
- if (choice == 'b')
- {
- cout << "You chose format B, Enter a time in 24-hour format: ";
- cin >> time;
- cout << endl;
- if (time >= 12)
- {
- timeType = "a.m.";
- time = time - 12;
- }
- if (time < 12)
- {
- timeType = "p.m.";
- }
- cout << "Your time converted : " << time << ":00 " << timeType;
- }
- if (choice == 'a')
- {
- cout << "You chose format A, Enter a time in 12-hour format: ";
- cin >> time;
- cout << "Enter the time type (a.m. or p.m.): ";
- cin >> input;
- cout << endl;
- if (input == 'p')
- {
- time = time + 12;
- }
- if (time < 10)
- {
- cout << "Your time converted : " << "0" << time << ":00 " << timeType;
- }
- else {
- cout << "Your time converted : " << time << ":00 " << timeType;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement