Thread: Problem with simple IF

  1. #16
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    Quote Originally Posted by iMalc View Post
    IMHO, it is wrong to be reading a time into a double in this way. It isn't stored in any useful way. You can't add 0.30 to advance by half an hour properly, for example. It should be read in as two seperate integers instead, using a colon to seperate the hours and minutes, which is more logical anyway.
    I completely agree with this. Use integers, avoids all sorts of problems. If you want to use only ONE number, use an integer to store number of minutes or seconds, and then use math to figure out how many hours, days, years etc the integer value corresponds to.

    I'm also agreeing that comparing float/double with == is bad idea, since floating point numbers are not always PRECISE. In particular 0.1 or multiple [except 0.5] are similar to 1/3 in decimal numbers - it is NEVER going to be precise in [binary] floating point formats.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  2. #17
    Registered User
    Join Date
    Jan 2005
    >> im no pro but you missed the { } on your if and else try this

    It's not necessary if the blocks consist of a single statement, although in many cases it is better practice to use the braces anyway.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A simple file I/O problem
    By eecoder in forum C Programming
    Replies: 10
    Last Post: 10-16-2010, 11:00 PM
  2. Problem in simple code.
    By richdb in forum C Programming
    Replies: 6
    Last Post: 03-20-2006, 02:45 AM
  3. Problem in very simple code
    By richdb in forum C Programming
    Replies: 22
    Last Post: 01-14-2006, 09:10 PM
  4. Simple Initialization Problem
    By PsyK in forum C++ Programming
    Replies: 7
    Last Post: 04-30-2004, 07:37 PM
  5. Simple OO Problem
    By bstempi in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2004, 05:33 PM