Pages

Friday 4 July 2014

Write a C++ 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.

code-
#include<iostream.h>
#include<conio.h>
void main()
{

   clrscr();

   int hours,mins,seconds,x;                         

   cout<<"Enter hours=";

   cin>>hours;

   cout<<"\nEnter minutes=";

   cin>>mins;

   cout<<"\nEnter seconds=";

   cin>>seconds;

   if(hours > 24)

    {

     cout<<"Invalid Entery";

   }

   else

   {

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

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

  
  if(hours > 12)

{

  hours=hours-12;

  cout<<"12 Hours Format\n";

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

  }

       else

  {

 cout<<"12 Hours Format\n";

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

  }

   }


}                            // end of main

6 comments:

  1. // Improved it a little logically, pardon the indentation and styling.
    #include
    #include
    using namespace std;
    int main()
    {
    int hours,mins,seconds,x;

    cin>>hours;
    cin>>mins;
    cin>>seconds;

    if(hours >= 24 || mins >= 60 || seconds >= 60)
    {
    cout<<"Invalid Time";
    }
    else
    {
    cout<<"24 Hours Format\n";
    cout< 12)
    {
    hours=hours-12;
    cout<<"12 Hours Format\n";
    if (hours < 10) {cout<<"0"<<hours<<":"<<mins<<":"<<seconds<<" pm";}
    else {cout<<hours<<":"<<mins<<":"<<seconds<<" pm";}
    }
    else
    {
    cout<<"12 Hours Format\n";
    cout<<hours<<":"<<mins<<":"<<seconds<<" am";
    }

    }
    return 0;
    }

    ReplyDelete
    Replies
    1. Write A C++ Program Take Hours, Minutes, Seconds And Print It In 24 Hours And Standard Format ~ Computer Science Magazine >>>>> Download Now

      >>>>> Download Full

      Write A C++ Program Take Hours, Minutes, Seconds And Print It In 24 Hours And Standard Format ~ Computer Science Magazine >>>>> Download LINK

      >>>>> Download Now

      Write A C++ Program Take Hours, Minutes, Seconds And Print It In 24 Hours And Standard Format ~ Computer Science Magazine >>>>> Download Full

      >>>>> Download LINK Je

      Delete
  2. We have been done so in our physics numerical but I dint know that the program has also established in order to perform the same function.

    ReplyDelete
    Replies
    1. IF YOU NEED NEUMERICAL PROGRAMME PLEASE CONTACT ME.

      Delete
  3. Write A C++ Program Take Hours, Minutes, Seconds And Print It In 24 Hours And Standard Format ~ Computer Science Magazine >>>>> Download Now

    >>>>> Download Full

    Write A C++ Program Take Hours, Minutes, Seconds And Print It In 24 Hours And Standard Format ~ Computer Science Magazine >>>>> Download LINK

    >>>>> Download Now

    Write A C++ Program Take Hours, Minutes, Seconds And Print It In 24 Hours And Standard Format ~ Computer Science Magazine >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete