Usually, seconds time is used in sports especially running. There are runners who time check their selves to check how long had they run in 60 seconds and more. This is used by seconds timers either digital or analog. Now, I made a program that converts seconds to days, minutes and seconds. This program is used with long data type identifier because we need to convert large numbers. Check out the sample codes below.
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
long seconds,days,mins,sec;
cout<<"Enter the number of seconds: ";
cin>>seconds;
days = seconds / 86400;
mins = (seconds / 60) - (days*1440) - (((seconds / 3600) - (days * 24)) * 60 );
sec = seconds % 60;
cout<<seconds<<" second/s = "<<days<<" days "<<mins<<" minutes "<<sec<<" seconds";
getch();
}
The program operates like this. At first we need to declare our variables with the long data type identifier to allow conversion with large numbers. When run, the program will ask the user to input seconds. Then it will be stored in the variable namely seconds. After that, your input (seconds) will undergo certain equations to get the equivalent days, minutes and seconds as seen above. Lastly, it will show you the result then you can now terminate the program. Check out the sample output below.
Hope you learned something from this lesson. Feel free to leave a comment below. Thanks!
Hope you learned something from this lesson. Feel free to leave a comment below. Thanks!
No comments:
Post a Comment
Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!