Thread: a little confuse o_0???

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    32

    a little confuse o_0???

    A year is a leap year if it is divisible by 4,however, if a year is divisible by 100, it must be divisible by 400 for it to be a leap year. Hence, 2000 is a leap year, but 1900 is not. Make a program that will input a value for year (int) and output whether it is a "Leap Year" or "Not a Leap Year".

    i'm a little confused about the logic about this T_T

    please someone can help me with these???

    thanks in advance

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    http://en.wikipedia.org/wiki/Leap_year#Algorithm

    Convert that to C/C++ code and post it here if it gives you trouble.

    gg

  3. #3
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    waaaaaaaaaaa....

    i still can't get it to work >_<

    i cant understand modulo T_T


    thnx a lot dude

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Post your code.

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

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    if year modulo 400 is 0 then leap
    else if year modulo 100 is 0 then no_leap
    else if year modulo 4 is 0 then leap
    else no_leap

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    if ((year modulo 4 is 0) and (year modulo 100 is not 0)) or (year modulo 400 is 0)
    then leap
    else no_leap

    [edit] Leap day

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    http://en.wikipedia.org/wiki/Modulo_operation

    As you can see in the table there, the C/C++ modulo operator is &#37;

    gg

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, so how would you make that into C++ code?

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

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    yeah i agree
    im a newbie
    so i cant really understand how to make it in C++ code

    for example

    the modulo of 4??

    how would you encode it in C++ ?

    please codeplug a little bit of understanding here

    please please....

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I would recommend a tutorial to get you up to speed on the basics on the language. Once you know the basics, converting the logic in post #5 is a breeze.

    http://www.cprogramming.com/tutorial.html#c++tutorial

    gg

  11. #11
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    main()
    { int year;

    clrscr();

    p("Enter a year: ");
    s("&#37;d",&year);

    if(year%4==0 && year%100==0 && year%400)
    p("The year %d is a leap year.",year);
    else
    p("The year %d is not a leap year.",year);


    i can't get the 1900 as not a leap year T_T

    still having problems with it huhuhu

  13. #13
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Compare your own post #5 with what you have actually implemented in your C-code.

    And a word of advice: Don't "make your own language" - printf() is a stanard function, don't use #define p printf and #define s scanf - it's just so much harder to read.

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

  14. #14
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    This being the C++ forum, consider using cout and cin instead . . . or post your thread in the C forum next time.

    Use code tags: [code] Code here [/code]
    And try to post complete code.

    Oh, and main() should return int. The implicit-int rule is deprecated.
    Code:
    int main() {
        /* ... */
        return 0;
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  15. #15
    Registered User
    Join Date
    Jan 2008
    Posts
    32
    hehehehe
    sorry for that dude....
    i just made that here since it is easy to write

    T_T

    thnx to all who replied....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PayPal confuse me
    By Akkernight in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 04-20-2009, 11:56 AM
  2. Simple Sorts Confuse ME =/
    By otchster in forum C Programming
    Replies: 5
    Last Post: 12-03-2005, 02:02 PM
  3. confuse about included files
    By C-Dumbie in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2002, 07:04 PM
  4. confuse with character array
    By dv007 in forum C Programming
    Replies: 6
    Last Post: 08-09-2002, 01:05 PM
  5. Too confuse
    By dv007 in forum C++ Programming
    Replies: 6
    Last Post: 07-25-2002, 05:33 PM