Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Problem in manipulating time in mins & secs !

Author: Dan Honeycutt

Date: 04:45:03 07/21/04

Go up one level in this thread


On July 21, 2004 at 03:45:39, Gopikrishna wrote:

>Time is passed as double.I preffered double instead of unsigned long because for
>outputting fraction of secs like 2.23 secs, double is more convenient.
>
>  So ttm is passsed as double.
> if ((ttm/1000) >=60)
>{
>	ttm=ttm/1000;
>             ms=ttm/60;
>	ttm=(ttm-(ms1*60));
>	min1=(int)ms1;
>}
>else
>ttm=ttm/1000;
>
>In the above ms is declared as double whereas min1 as int.
>So when I print time as,
>Printf("Total time:%d min:%2.2f secs",min1,ttm);
>
>  So when time was passed as 61000 (or 61secs), its outputting as
>Total time:0 min:-61.00 sec
>Strange!!! Also another problem is its in minus.
>It should have been 1 min:1 sec.So am i doing anything wrong in the above?
>Actually I could have passed time as unsigned long instead of double but as you
>can see I want that secs to be accurate like 2.23 secs instead of 2 secs !
>  So please help me.Thanks.


I think what you're trying to do is:

double sec = ttm/1000;
int min = 0;
if (sec >= 60) {
  min = (int) sec/60;
  sec = sec - 60 * min;
}
printf("Total time:%d min:%2.2f secs",min,sec);

Dan H.




This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.