Navigation Bar

Showing posts with label hour. Show all posts
Showing posts with label hour. Show all posts

Program to Convert Military Time to Standard time (12 OR 24 Hours)

  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int hours,mins,seconds;
  7. bool status = true;
  8. cout << "Enter Hours (00-23): "; cin >> hours;
  9. cout << "Enter Minutes (00-59): "; cin >> mins;
  10. cout << "Enter Seconds (00-59): "; cin >> seconds;
  11. if((hours >= 24 || hours < 0))
  12. {
  13. cout<<"\nInvalid Hours.."; status=false;
  14. }
  15. if((seconds >= 60 || seconds < 0))
  16. {
  17. cout<<"\nInvalid Seconds.."; status=false;
  18. }
  19. if((mins >= 60 || mins < 0))
  20. {
  21. cout<<"\nInvalid Minutes.."; status=false;
  22. }
  23. if(status)
  24. {
  25. cout<<"\n24 Hours Format\n";
  26. cout << "Hours: " << hours << endl;
  27. cout << "Minutes: " << mins << endl;
  28. cout << "Seconds: " << seconds << endl;
  29. if(hours > 12)
  30. {
  31. hours-=12;
  32. }
  33. cout<<"\n\n12 Hours Format\n";
  34. cout << "Hours: " << hours << endl;
  35. cout << "Minutes: " << mins << endl;
  36. cout << "Seconds: " << seconds << endl;
  37. }
  38. return 0;
  39. }

Output: