Problem!

This is a discussion on Problem! within the C++ Programming forums, part of the General Programming Boards category; I am doing a project that has the user input any year ranging from 1900 to 2099 and it will ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    Problem!

    I am doing a project that has the user input any year ranging from 1900 to 2099 and it will display what year easter sunday was on. The equation I have works for every year except 1954, 1981, 2049, 2076. Now my code works for every other year excpet these. I always get the day for these years to come up seven days ahead of what it should. Could someone look at my code and see if they can find a problem.

    #include <iostream>
    #include <math.h>
    #include <iomanip.h>

    int main()
    {
    int year;

    cout << "Easter Sunday Calculator" << endl;
    cout << "Enter the year: ";
    cin >> year;

    int a = year % 19;
    int b = year % 4;
    int c = year % 7;
    int d = ( 19 % ( a + 24 ) ) % 30;
    int e = ( 2 * ( b + 4 ) * ( c + 6 ) * ( d + 5 ) ) % 7;
    int day = 22 + d + e;

    if ( ( day <= 31 ) && ( year != 1954, 1981, 2049, 2076 ) )
    {
    cout << "March " << day << endl;
    }
    else if ( ( day > 31 ) && ( year != 1954, 1981, 2049, 2076 ) )
    {
    day = day - 31;
    cout << "April " << day << endl;
    }
    else
    {
    day = day - 38;
    cout << "April " << day << endl;
    }
    return 0;
    }

  2. #2
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Don't have time to search the bug, but click
    here for a general solution.

    Lots of algorythms, you'll find here everything you need.
    Pretty complicate, though, but it's well-explained.

    Have fun!
    Last edited by Carlos; 10-04-2001 at 03:59 AM.

  3. #3
    zoo
    Guest
    Try this:

    if ( ( day <= 31 ) && ( year != 1954 && year != 1981 && year != 2049 && year != 2076 ) )
    {
    cout << "March " << day << endl;
    }
    else if ( ( day > 31 ) && ( year != 1954 && year != 1981 && year != 2049 && year != 2076 ) )

  4. #4
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    Well, zoo, I think Nate was using just an abbreviation here,
    (year != 1954, 1981, 2049, 2076), such code won't compile at all . So, not that's the real problem here, I guess.

  5. #5
    zoo
    Guest
    Carlos, actually such code will compile. Give it a try.

    Regards,
    zoo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

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