CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Convert minutes in hours

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
bauche



Joined: 06 Nov 2010
Posts: 22
Location: montreal qc

View user's profile Send private message Send e-mail

Convert minutes in hours
PostPosted: Tue Nov 16, 2010 6:17 am     Reply with quote

Hi there i need your help..!!!
i built a counter 6 digit the fist 4 digit is hour the last 2 one is minute
0000:00

i have two variable add together to add time in the counter...prob is if i have like 58 minutes and want to add 3 minutes the result on display is 0000:61

i want to convert this in hour...0001:01
i tried:
Code:

if (minutes == 60)
{
hours++; x1 = 1;
}

60 work!!!
61 or more dont work (past true) i've tried > or >= instead of ==
same prob...
and if i have 55 minutes and i want to add 20 make 75...should be
0001:15
Thanks for help!!!!!
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Tue Nov 16, 2010 7:24 am     Reply with quote

Code:
if (minutes == 60)
{
hours++;
x1 = 1;
minutes-=60;
}


.... from what i understand reading your code... that should do it.

hope that helps..

Gabriel
_________________
CCS PCM 5.078 & CCS PCH 5.093
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Tue Nov 16, 2010 10:08 am     Reply with quote

Not "if (minutes == 60)", it should be "while (minutes >= 60)".
Code:
while (minutes >= 60)
{
hours++;
x1 = 1;
minutes-=60;
}

_________________
Andrew
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Tue Nov 16, 2010 11:17 am     Reply with quote

or how about:

Code:
if(minutes==60)
{
   minutes=1; //if this was set to 0 then it would count 61 minutes per hour
   hours++;
}
else
{
   minutes++;
}

_________________
Vinnie Ryan
bauche



Joined: 06 Nov 2010
Posts: 22
Location: montreal qc

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 16, 2010 7:05 pm     Reply with quote

Finally it's works!!!!

Code:


if (minutes >=60)
{
hours = hours + 1;
minutes = minutes - 60;
}



Thanks all for Help ...very appreciated.... Smile

We knows how to do it now!!!!!
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Tue Nov 16, 2010 7:19 pm     Reply with quote

That's the same exact thing that andrewg posted.

Code:

while (minutes >= 60)
{
hours++;
x1 = 1;
minutes-=60;
}


hours = hours + 1;
is the same as
hours++;


minutes = minutes - 60;
is the same as
minutes-=60;
_________________
Vinnie Ryan
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group