help loll

This is a discussion on help loll within the C++ Programming forums, part of the General Programming Boards category; well im trying to do this but i cant first i make a class in c++ and then pass values ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    72

    help loll

    well im trying to do this but i cant

    first i make a class in c++ and then pass values to it from main function of time

    lets say i pass 3:26:12 ..

    3 = hour
    26 = min
    12 = sec

    so it displays it fine.. but now i want abit change in it.. i want if i pass 3:65:12 to it so it should automaticaly make it 4:05:12 as we know tht 1 hour = 60 mins..

    so any logic for that? thanks buddies in advance

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Yes. In fact you have the logic in your post.

    (In other words, what exactly is your question?)

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    loll!

    How about boost::date_time?

  4. #4
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    ok let me explain again lol..

    once the program is executed, iit will ask u to set a time..

    if u enter => 3:25:10 it will display it as follows

    The Time is 3:25:10

    in this, 3 = hour .. 25 = minutes .. 10 = seconds .. i hope this is very clear

    now i wnt if someone enter's => 3:65:10 ... it means 3 = hour ... 65 = minute .. 10 = second.. we know that 1 hour has 60 minutes.. so minutes CANNOT BE MORE THAN 60 else the time will change to 4.. so with this logic it should be 4:05:10 .. now i hope this is very clear.. i need the logic for this..... i tried but couldnt get it

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, what have you tried, and how is the result different from what you expect?

    --
    Mats
    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.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    as i said, i dont know the logic.. i can write the code if u can tell me the logic mtsp

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by salmansalman View Post
    as i said, i dont know the logic.. i can write the code if u can tell me the logic mtsp
    You know the logic -- how else did you get the answer 4:05:10? (Whatever you did to get that answer -- that's the logic.)

  8. #8
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    i dont know what to do to get the answer, thats the problem.. i know what it should be but i dont know HOW it should be.. by logic i meant i dont know the mathematical logic for it

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You said the minutes can't be more than 60. So: IF the minutes are more than 60, you need to fiddle. How did you get 4 and 05 out of 3 and 65?

    Edit: And continuing that idea, what should happen to 3:83? What about 11:64? What about 12:72?

  10. #10
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    i did if(min>60)
    cout<<"Invalid input";
    looool thats the easy escape =[ n i dont know do i need to use ifs or what man.. cant u write the logic code here?

  11. #11
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    If your using a class, ensure the members are a default state ( zero ) to begin. As each time is entered, use a function that checks the validitlity of the value, and enusre it never goes over 60, if it does, print an error and quit, or get the function to set it to a default value.

    As for printing the time, use getter functions to return the valid time values seperated by the colon.
    I'm just trying to be a better person - My Name Is Earl

  12. #12
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    This has just *got* to be a joke...really, seriously. Epic lulz, right? ROFLcopter, all that?

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by salmansalman View Post
    i did if(min>60)
    cout<<"Invalid input";
    looool thats the easy escape =[ n i dont know do i need to use ifs or what man.. cant u write the logic code here?
    No. (I can write the logic code, but I can't write the logic code here, in that that would waste my time and enable your behavior. And don't ask me in a PM or email either.)

    If you don't understand the logic well enough to at least get a flowchart or pseudocode out of it, then showing you C++ isn't going to help you. Show us that you understand what's going on, and we can help with the details.

  14. #14
    Registered User
    Join Date
    Apr 2008
    Posts
    72
    thanks for the lecture, i dont hve time to read tht much useless paragraphs full of arrogant lines.. ill figur it out myself, cya.. thts all for now
    bye

  15. #15
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Although everything tabstop said was perfectly valid. Nobody will write an entire program for you, if you start the program then post it in regaurds to any errors people can help you.
    I'm just trying to be a better person - My Name Is Earl

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

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