Advertisement
Guest User

24hour to normal

a guest
Sep 30th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6. int hours;
  7. int minutes;
  8. bool am = true;
  9. bool pm = false;
  10.  
  11. cout<<"Input the hour: "<<endl;
  12. cin>>hours;
  13.  
  14. cout<<"Input the minutes: "<<endl;
  15. cin>>minutes;
  16.  
  17. if(hours > 24 || hours < 1)
  18. {
  19.     cout<<"Please eneter a number between 1 and 24";
  20.     return 0;
  21. }
  22.  
  23. if(minutes > 60 || hours < 1)
  24. {
  25.     cout<<"Please eneter a number between 1 and 60";
  26.     return 0;
  27. }
  28.  
  29. if(hours >= 12 && hours <= 24 )
  30. {
  31.     hours -= 12;
  32.     pm = true;
  33.     am = false;
  34. }
  35. else{
  36.     am = true;
  37. }
  38.  
  39. if(pm == true)
  40. {
  41.     cout<<hours<<":"<<minutes<<" PM"<<endl;
  42. }
  43. else if(am == true)
  44. {
  45.     cout<<hours<<":"<<minutes<<" AM"<<endl;
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement