a little confuse o_0???

This is a discussion on a little confuse o_0??? within the C++ Programming forums, part of the General Programming Boards category; A year is a leap year if it is divisible by 4,however, if a year is divisible by 100, it ...

  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,676
    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,676
    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,676
    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,047
    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,047
    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....

Page 1 of 2 12 LastLast
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, 01:02 PM
  3. confuse about included files
    By C-Dumbie in forum C++ Programming
    Replies: 2
    Last Post: 12-31-2002, 06: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

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