Register to reply

C program display time

by mathrocks
Tags: display, program, time
Share this thread:
mathrocks
#1
Oct1-06, 02:02 PM
P: 106
Ok, I have to write a program that displays an arbitary time. I'm given 2 ticks every 1 second. So I'm suppose to use that to display the Hour, minute and seconds...im not sure where to start on how to create this. I know to find seconds I just do ticks/2, but for minutes and hours I'm confused...
Phys.Org News Partner Science news on Phys.org
Scientists discover RNA modifications in some unexpected places
Scientists discover tropical tree microbiome in Panama
'Squid skin' metamaterials project yields vivid color display
chroot
#2
Oct1-06, 02:04 PM
Emeritus
Sci Advisor
PF Gold
chroot's Avatar
P: 10,427
So your program is given an integer -- represented in ticks -- and you just need to convert ticks into seconds, minutes, hours, etc?

I'd suggest you look into using the / (integer division) and % (modulo) operators.

- Warren
mathrocks
#3
Oct1-06, 02:34 PM
P: 106
Quote Quote by chroot
So your program is given an integer -- represented in ticks -- and you just need to convert ticks into seconds, minutes, hours, etc?

I'd suggest you look into using the / (integer division) and % (modulo) operators.

- Warren
Yes, that's correct. So if I do the following
seconds=ticks*2
minutes=seconds/60
hours=minutes/60

how do I then use those values to display the correct hours, minutes?

for example I have 3602 seconds, that will be 60.0333333 minutes, and 1.00055556 hours

chroot
#4
Oct1-06, 03:30 PM
Emeritus
Sci Advisor
PF Gold
chroot's Avatar
P: 10,427
C program display time

You're not understanding me. The best solution uses BOTH the % and / operators.

If you divide 3602 seconds by 3600 seconds (1 hour in seconds) with integer division, the answer will be 1. This is the number of hours.

If you then perform the same divison, but take the remainder (using the % operator), the remainder is 2.

Perform the integer division 2 / 60 (1 minute in seconds). The answer will be 0. This is the number of minutes.

Perform the same division, but keep the remainder (2 % 60), which will be 2. This is the number of seconds.

- Warren


Register to reply

Related Discussions
Program to display student number Computing & Technology 0
How to calculate program execution time? Programming & Computer Science 4
Astro simulation program problem - program bugs? Astronomy & Astrophysics 4
Develop a program to display a number, on a single 7 segment LED display Computing & Technology 6
Display a number, on a single 7 segment LED display Introductory Physics Homework 0