Logical! Logical! Why do you have to be so Logical?

This is a discussion on Logical! Logical! Why do you have to be so Logical? within the C Programming forums, part of the General Programming Boards category; Originally Posted by rags_to_riches Shouldn't there be some sort of subtraction involved in your algorithm there? That would help :-)...

  1. #16
    Registered User g8ortech14's Avatar
    Join Date
    Oct 2007
    Location
    Orlando FL
    Posts
    22
    Quote Originally Posted by rags_to_riches View Post
    Shouldn't there be some sort of subtraction involved in your algorithm there?
    That would help :-)

  2. #17
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Let me give you a little hint on a different way to do this...

    Code:
    #define SecInMin = 60 
    #define SecInHr = SecInMin * 60
    #define SecInDay = SecInHr * 24
    Can you think of a way to use this with what you're trying to do?

  3. #18
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461
    Quote Originally Posted by g8ortech14
    Minutes are still calculating incorrectly ? Grrr! I feel stupid. I make it happen on paper, but can't translate to C.
    You might want to review my suggestion in post #7. To find out the number of hours when given the total number of seconds, make use of the number of seconds in an hour. The same idea applies to find out the number of minutes.

    In fact, I suspect that CommonTater has the same idea that I have in mind. So, make use of CommonTater's hint in post #17, but be aware that the code snippet provided has errors of a rather common variety (but that gives you a chance to fix them, which is good practice ).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #19
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    laserlight...

    You wanna tell me what is wrong with my 3 #define statements?
    Really... how much COULD be wrong with it?

  5. #20
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,409

    .

    i dunno, maybe using assignment operators?
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  6. #21
    Registered User Char*Pntr's Avatar
    Join Date
    Sep 2007
    Location
    Lathrop, CA
    Posts
    198

    Wink

    Quote Originally Posted by laserlight View Post

    (snip) , but be aware that the code snippet provided has errors of a rather common variety (but that gives you a chance to fix them, which is good practice ).
    Shouldn't

    Code:
    #define SecInMin = 60 
    #define SecInHr = SecInMin * 60
    #define SecInDay = SecInHr * 24
    be:

    Code:
    #define SecInMin  60 
    #define SecInHr  SecInMin * 60
    #define SecInDay  SecInHr * 24
    ??

    hey thanks for the practice! I needed that. :-)

    EDIT:
    rogster001, I was laughing so hard at:
    "You wanna tell me what is wrong with my 3 #define statements?
    Really... how much COULD be wrong with it?"
    that I did not notice your post. I hate wasting my PostCounts
    on things like this.
    Last edited by Char*Pntr; 09-18-2010 at 10:51 AM.

  7. #22
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by CommonTater View Post
    laserlight...

    You wanna tell me what is wrong with my 3 #define statements?
    Really... how much COULD be wrong with it?
    You'd be surprised!

    I recall putting a semi-colon at the end of a few. <ACK!>

  8. #23
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461
    Quote Originally Posted by Char*Pntr
    hey thanks for the practice! I needed that. :-)
    The practice was not for you though
    In order to avoid potential problems with grouping, and making use of a common convention of fully capitalising macro names, they should actually be:
    Code:
    #define SEC_IN_MIN 60 
    #define SEC_IN_HR (SEC_IN_MIN * 60)
    #define SEC_IN_DAY (SEC_IN_HR * 24)
    though it seems that SEC_IN_DAY is not needed here.

    Quote Originally Posted by Adak
    I recall putting a semi-colon at the end of a few.
    Me too
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #24
    Registered User g8ortech14's Avatar
    Join Date
    Oct 2007
    Location
    Orlando FL
    Posts
    22
    Hi all I figured it out late Saturday, and have been busy with family and school since then. Thank you so much for the input. Laserlight you helped me without giving me the answer. There were a few others that gave me some direction as well. I figured out that I was making my if/else statements to complex. I think at one point while testing I like 6 if/else statements. All I need is 2 and that resolved it. I actually enjoyed the process of figuring out the answer. i'm happy to share what I came up with, but don't want to post the answer in case another student comes here looking for the answer. Anyway thanks again.

  10. #25
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,831
    You don't need to use 'double' for hours, mins, seconds. Integer should be fine. Change printf()ís formatting appropriately.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Physical and Logical Memory.
    By TheUmer in forum General Discussions
    Replies: 3
    Last Post: 11-04-2010, 04:28 AM
  2. Logical And
    By shiju in forum C Programming
    Replies: 6
    Last Post: 01-11-2004, 10:15 AM
  3. Logical Error
    By gardenair in forum C Programming
    Replies: 2
    Last Post: 04-06-2003, 04:18 PM
  4. Size of 1 pixel
    By ooosawaddee3 in forum C++ Programming
    Replies: 4
    Last Post: 07-26-2002, 08:06 PM
  5. logical operators
    By sballew in forum C Programming
    Replies: 4
    Last Post: 09-04-2001, 06:24 PM

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