How would i do this????

Im suppose to write a program that inputs an amount of time in whole seconds. The program should compute and output the time in weeks,days,hours,minutes,and seconds, using the larger units as much as possible. For example 1000 seconds and the output would be 0 weeks, 0 days, 0 hours, 16 minutes, 40 seconds....I would appreciate if someone could help me with the layout of how to do this.
convert seconds to minutes if you have over 60 seconds
then convert minutes to hours if you have over 60 minutes
then hours to days if you have over 24 hours
etc
etc
Ohh
i tried putting 1 mind is 20 sec...1 hour is 60 min..1 day is 24 hours ..1 week is 7 days.. but i dont think how i wrote it is correct
could you show me how you would write it? the layout or how should it look?
i meant 1 min is 60 sec (typo)
I don't like to get in the habit of doing people's assignments for them ;P

If you understand the concept you should be able to write your own. Think about how you would do this "by hand"?

in your original post:

For example 1000 seconds and the output would be 0 weeks, 0 days, 0 hours, 16 minutes, 40 seconds


How did you know that 1000 seconds = 16 minutes, 40 seconds? What kind of math or logic did you do? Break down the process into simple steps, then write code which represents those steps.
i ddnt kno that was the example program i put 1000 seconds and it gave me that ouput ...thats what im trying to do but idk how im confused because of the format...im not sure how
Actually you're lucky, I did the same thing about a year ago and it was handy.

Following code takes in the current time in seconds and converts into days, hours and seconds format. You can modify it into weeks, months, years......
It converts the display time into string format though. You can definitely optimize it more, if that's your purpose. It was really a quick fix, that I wanted as part of a bigger project.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
char *getCurTimeInHourFormat(int currentTime)
{
       char *hourFormat = new char(200);
       int hour = 00;
       int min = 00;
       int sec = 00;
       char buffer[100];

       if(currentTime > 0)
      {
             if(currentTime > 59)
            {
	   if(currentTime > 3599)
	   {
		   hour = currentTime/3600;
		   currentTime = currentTime%3600;
		   cout << "hour= " << hour<< endl;
	   }
	   min = currentTime/60;
	   currentTime = currentTime%60;
	   cout << "min = " << min << endl;
            }

            sec = currentTime;

            cout << "sec = " << sec << endl;
     }

     char *test1 = strcat(itoa(hour, buffer, 10), ":" );
     cout << "test1 = " << test1 << endl;

     char *test2 = strcat(itoa(min, buffer, 10), ":");
     cout << test2 << endl;
	   
     char *test3 = strcat(itoa(sec, buffer, 10), ":");
    cout << test3 << endl;

    hourFormat = strcat(strcat(test1, test2), test3);
   cout << "Final = " << hourFormat << endl;

}
Topic archived. No new replies allowed.