-->




Program take hours, minutes, seconds and print it in 24 hours & standard format

4 comments
 C++ program to display hours minutes and seconds in both  12 and 24 hours format:
24 Hours format : 23:30:12
Standard format : 11:30:12 pm
C++ CODE using Turbo C++ IDE.



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {

  5.    clrscr();

  6.    int hours,mins,seconds,x;                         

  7.    cout<<"Enter hours=";

  8.    cin>>hours;

  9.    cout<<"\nEnter minutes=";

  10.    cin>>mins;

  11.    cout<<"\nEnter seconds=";

  12.    cin>>seconds;

  13.    if(hours > 24)

  14.     {

  15.      cout<<"Invalid Entery";

  16.    }

  17.    else

  18.    {

  19.        cout<<"\n24 Hours Format\n";

  20. cout<<"Hours  :  Mins  :  Seconds\n"<<"  "<<hours<<"  :     "<<mins<<"   :     "<<seconds<<"\n";

  21.   
  22.   if(hours > 12)

  23. {

  24.   hours=hours-12;

  25.   cout<<"12 Hours Format\n";

  26. cout<<"Hours  :  Mins  :  Seconds\n"<<"  "<<hours<<"  :     "<<mins<<"   :     "<<seconds;

  27.   }

  28.        else

  29.   {

  30.  cout<<"12 Hours Format\n";

  31.  cout<<"Hours  :  Mins  :  Seconds\n"<<" "<<hours<<": "<<mins<<"   :        "<<seconds;

  32.   }

  33.    }

  34. }                            // end of main


4 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. this one one problem 1 hour has 60 mins when you enter a value greater than 60 its still uses it and displays it as out put

    ReplyDelete
  3. i don't get the output correct by this program

    ReplyDelete