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.
24 Hours format : 23:30:12
Standard format : 11:30:12 pm
C++ CODE using Turbo C++ IDE.
- #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
This comment has been removed by the author.
ReplyDeletethis 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
ReplyDeleteits rong
ReplyDeleteyour right
Deletei don't get the output correct by this program
ReplyDeleteare you a member of bitcoin
DeleteThis code did not work for me could someone please help with fixing the code
ReplyDeleteIt says error while compiling. the last else is said to be "Misplaced". But I have typed the same code given here
ReplyDelete
ReplyDeletenice but i think u have to post new kinds of projects
what is this clrscr(); mean? and how to use it?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteint main() {
ReplyDeleteint 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;
}