-->





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

 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


13 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
  4. This code did not work for me could someone please help with fixing the code

    ReplyDelete
  5. It says error while compiling. the last else is said to be "Misplaced". But I have typed the same code given here

    ReplyDelete

  6. nice but i think u have to post new kinds of projects

    ReplyDelete
  7. what is this clrscr(); mean? and how to use it?

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
  10. int main() {

    int hour, min, second;
    cin >> hour >> min >> second;

    cout << "Enter Hours, Minute and second \n";


    if (hour > 24 || min > 60 || second > 60)
    {
    cout << "Invalid Entry\n\n";
    }

    else
    {
    cout << "\n24 Hours Format\n";
    cout << "Hours : Mins : Seconds\n" << " " << hour << " : " << min << " : " << second << '\n';
    }

    if (hour > 24 || min > 60 || second > 60)
    {
    cout << "Invalid Entry\n\n";
    }

    else if (hour > 12)
    {
    hour = hour - 12;

    cout<<"12 Hours Format\n";
    cout << "Hours : Mins : Seconds\n" << " " << hour << " : " << min << " : " << second << " PM\n";
    }

    else
    {
    cout<<"12 Hours Format\n";
    cout << "Hours : Mins : Seconds\n" << " " << hour << " : " << min << " : " << second << " AM\n";
    }

    return 0;
    }

    ReplyDelete