# float to integer

This is a discussion on float to integer within the C Programming forums, part of the General Programming Boards category; how can I display the integer value of a variable... e.g. say I have a variable t1 ( to represent ...

1. ## float to integer

how can I display the integer value of a variable...

e.g. say I have a variable t1 ( to represent time ) which is entered from the keyboard and has a value of 1525 ( 3.25pm) and I divide this by 100 to give the hours as 15 how do I print this on the screen....which is technically calculating hours and minutes and breaking 1525 into 2 parts... 15 and 25
In Basic I can say ti = int( t1/100) but in Turbo C I cannot do this..

I an converting a program from QBasic to Turbo C ( Supplied as study material ) and can`t work it out.......

portion of code I am trying to do is..... ( In QBasic )

input"",t1
input "",t2
h1 = int(t1 / 100)
m1 = t1 - (h1 * 100)
h2 = int(t2 / 100)
m2 = t2 - (h2 * 100)
diff = int(h2 * 60 + m2) - (h1 * 60 + m1)
dh = int(diff / 60)
dm = diff -(dh * 60)

print dh,dm

Any help would be appreciated...

2. For input, use something like scanf.
For output, use something like printf.

For the rest, declare variables for each of the names you use. Then just do the math.

int h1, t1, m1, h2, t2, m2, diff, dh, dm;

h1 = t1 / 100;
m1 = t1 - ( h1 * 100 );
... and so on ...

printf("%d %d", dh, dm );

Quzah.

3. ## trying

thanks for that quzah...... i`ll try it... will let you know