Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help With Procedure!!!!!! PLEASE

Status
Not open for further replies.

Horsleym

Programmer
Oct 9, 2001
9
GB
Hi im currently using Delphi 6 at college and need to right a procedure which inputs a number of seconds from the user and then turns them into hours minutes and seconds!

Ive got so far and now im stuck. This is as far as ive got!

const secondsinminute = 60;
secondsinhour = 3600;
minutesinhour = 60;

var x, w, y, z :integer;

begin
write (Display, 'This procedure will ask you for a number of seconds');
getInt (x, 'Please enter a number of seconds:');
w:= x div daysinweek;
writeln (Display);
write (Display, 'Number of hours is:');

Ive got my variables ready and I know I have to use the div and mod commands.

CAN ANYONE PLEASE HELP ME

Thanks In advanc

Mark
 
Do you know how you would do it on paper?

You need to know how to do it by hand before you can code it. Getting the code from some developer on tek-tips isn't going to help you in the long run...

TealWren
 
yea i do know i just need help on this one code
 
Write it in english and I'll help you translate it to code TealWren
 
Ok

a user enters 7000 seconds!

I want that figure to come out as in HOURS:MINUTES:SECONDS

Im just stuck about using mod & div and the x, y, etc variables

 
div is just normal division but on integers.

So

5 div 5 = 1
36 div 6 = 6
12 div 5 = 2

mod gives the remainder upon division

So

12 / 5 = 2 r2
ie 12 mod 5 = 2

10 mod 3 = 1

Finally, if x = 7000 (sec),

x mod 3600 would give you the number of hours etc
(3600 secs in an hour)
 
23 div 5 = 4

23 mod 5 = 3
But what is this daysinweek variable? S. van Els
SAvanEls@cq-link.sr
 
DIV gives you the division answer without the decimal places. MOD gives you an integer remainder.

So if you have
const     secondsinminute = 60;
        secondsinhour = 3600;

and they put in 7000 minutes, you could use 7000 div secondsinhour to get how many hours. Then you want to know how many seconds aren't part of a whole hour, so you can use 7000 mod secondsinhour to find out how many seconds are left. Then you can use secondsleft div secondsinminute to find the minutes, and secondsleft mod secondsinminute to find the seconds.

Hope that makes sense... Good luck. TealWren
 
Hi Horsleym,

What I would do is something like this,

I would take the user input and div it with 3600 to get the
number of hours, then i would figure out the remainder with
mod and div that with 60 to get the number of minutes and
then you have the number of seconds left. I would use
variables to get these number and finally just concat them
into one big happy string :)

So with my idea you would have four variables. Namely:
1. UserInputInSeconds: integer;
2. NumberOfHours: integer;
3. NumberOfMinutes: integer;
4. NumberOfSeconds: integer;
5. HoursMinutes: string;

To convert integers to strings just use IntToStr() and to concat just use the + operator it's faster than the concat function. Then just assign the string to a label or
something.

I hope this helps,

BobbaFet Everyone has a right to my opinion.
E-mail me at cwcon@programmer.net
 
Thanks alot guys ur so very helpful! this has really helped me alot

Thanks again!

Mark

:)
 
Hi Mark,

Just a bit of advice. You can choose to take it or ignore it.

I think it's worthwhile spending a lot of time (especially when you're just starting out) thinking about how to solve your problem. Writing some ideas or formulas on paper might help and if you get really stuck you could just go crazy and experiment with bogus looking solutions- one of them may just work.

The reason I say this is that problem solving is one of the most essential tasks to programming. If you get a lot of practise then I'm sure you will be a very capable programmer.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top