Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main (){
  5. char choice, input;
  6. string timeType;
  7. int time;
  8. cout << "Format A: 12-hour to 24-hour" << endl;
  9. cout << endl;
  10. cout << "Format B: 24-hour to 12-hour" << endl;
  11. cout << endl;
  12. cout << "Enter the lowercase letter of the format you wish to use: ";
  13. cin >> choice;
  14. if (choice == 'b')
  15. {
  16. cout << "You chose format B, Enter a time in 24-hour format: ";
  17. cin >> time;
  18. cout << endl;
  19. if (time >= 12)
  20. {
  21. timeType = "a.m.";
  22. time = time - 12;
  23. }
  24. if (time < 12)
  25. {
  26. timeType = "p.m.";
  27. }
  28. cout << "Your time converted : " << time << ":00 " << timeType;
  29.  
  30. }
  31. if (choice == 'a')
  32. {
  33. cout << "You chose format A, Enter a time in 12-hour format: ";
  34. cin >> time;
  35. cout << "Enter the time type (a.m. or p.m.): ";
  36. cin >> input;
  37. cout << endl;
  38. if (input == 'p')
  39. {
  40. time = time + 12;
  41. }
  42. if (time < 10)
  43. {
  44. cout << "Your time converted : " << "0" << time << ":00 " << timeType;
  45. }
  46. else {
  47. cout << "Your time converted : " << time << ":00 " << timeType;
  48. }
  49.  
  50.  
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement