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. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    Question 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. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Oct 2002
    Posts
    2

    Smile trying

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assignment HELP!!
    By cprogrammer22 in forum C Programming
    Replies: 35
    Last Post: 01-24-2009, 01:24 PM
  2. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  3. No Match For Operator+ ???????
    By Paul22000 in forum C++ Programming
    Replies: 24
    Last Post: 05-14-2008, 10:53 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09:43 AM
  5. Repetition in do{}while
    By Beast() in forum C Programming
    Replies: 25
    Last Post: 06-16-2004, 10:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21