#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0

    Easter Day Calculator


    Hi,

    As part of a college assignment we have been tasked to design a program that will calculate the date of Easter day for a range of years from 1583 onwards.

    Basically the end user has to be able to enter any range of years (to a maximum of 100) and the program will tell them when easter day is for the given years.

    So far I have the program working for when an individual year is put in, but i don't know how enter a range of years and get the required results.

    Any help would be much appreciated, as I don't know what to research next to solve this problem.

    Thanks in advance

    Chris
  2. #2
  3. Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jun 2005
    Posts
    5,964
    Rep Power
    4851
    Use a loop, accessing the next year on each iteration of the loop.

    If you decide to post code for help with something, be sure and read the "How to Post" thread first.
    Write no code whose complexity leaves you wondering what the hell you did.
    Politically Incorrect DaWei on Pointers Grumpy on Exceptions
  4. #3
  5. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,073
    Rep Power
    1802
    Not sure how you got that far and yet still find this part difficult. You just do what you are doing but for each year in the range. Something like:
    Code:
    void ShowEaster( int first_year, int last_year )
    {
        for( year = first_year; year <= last_year; year++ )
        {
            Easter( year ) ;
        }
    }
    Clifford
  6. #4
  7. No Profile Picture
    Closet coder
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Feb 2005
    Location
    Plantation, FL <---south florida
    Posts
    1,431
    Rep Power
    153
    curious, when you say range of years are you asking the user input for "How many Years?"> and expect something like 50 or are you needing the actual year range from lets say 1980->2000?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0
    Thanks for all the replys, I have posted the code that I have so far. The assignment is a little vague, it simply says "Write a C program that allows the user to enter a range of years (maximum 100) anytime after 1582 and for each year displays the date Easter Sunday falls on".

    I think this means that they enter a range of years (for example 1970 - 2000) and it will give easter day for all the years in between.


    Again thanks for your time, it is much appreciated.

    PHP Code:
    #include <stdio.h>
    #include <stdlib.h>

    int main(int argcchar *argv[])

    {
    int year,day;                                                                                       //Declarations
    int k,a,b,c,q,p,m,d,n,e;                                                                        //Declaration of Variables

      
    printf("THIS PROGRAM WILL TELL YOU THE DATE OF EASTER DAY");                                  //Title
      
    printf("\n\nPlease insert the range of years for which you would like to know when Easter Day is:");   //Input Year(s)
      
    scanf("%d",&year);                                                                            //Read in the Year(s)
      
      
    year/100;                                                                                 //Calculates k
      
    year%19;                                                                                  //Calculates a
      
    year%4;                                                                                   //Calculates b
      
    year%7;                                                                                   //Calculates c
      
    = (3*k+3)/4;                                                                                //Calculates q
      
    = (8*k+13)/25;                                                                              //Calculates p
      
    = (15+q-p)%30;                                                                              //Calculates m
      
    = (19*a+m)%30;                                                                              //Calculates d
      
    = (4+q)%7;                                                                                  //Calculates n
      
    = (2*b+4*c+6*d+n)%7;                                                                        //Calculates e
      


      
    if (d+e<=9)
    {
                 
    day 22+d+e;
                 
    printf("The day is the %dth",day);
                 
    printf("\n\nThe Month is March\n\n");
    }
      else if (
    d==29e==6)

                 
    printf("The day is the 19th");
                 
    printf("\n\nThe Month is April\n\n");
                 
    }

     else if (
    d=28,e==6,a>10)
    {
                 
    printf("The day is the 18th");
                 
    printf("\n\nThe Month is April\n\n");
    }

     else 
     
    {
                 
    day d+e-9;
                 
    printf("The day is the %dth",day);
                 
    printf("\n\nThe Month is April\n\n");
    }
          
      
      
      
      
    system("PAUSE");    
      return 
    0;

  10. #6
  11. Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jun 2005
    Posts
    5,964
    Rep Power
    4851
    In the first place, you show nothing that establishes a range of years. When you finally get around to meeting that requirement, you are going to need a loop, as mentioned in your initial responses, which you seem to have skipped. One wonders why we bothered to make them.

    Secondly, I think you better have a look at what the comma operator does and rethink your expressions.

    Thirdly, you're wasting printf statements. No wonder the economy is in the tank.

    Finally, read about scanf and its return value. Your program goes in the crapper as soon as the user enters anything that can't be converted to a valid year. Users will do that, whether accidentally, maliciously, or whatever.
    Write no code whose complexity leaves you wondering what the hell you did.
    Politically Incorrect DaWei on Pointers Grumpy on Exceptions
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0
    sizeable grin, thanks for your "constructive" criticism

    I use the term constructive loosely, helpful as your comments were they come across as a little ostentatious

    I managed to get the program running now (with loops, thanks.)

    I've also taken out a few of the printf statements, so maybe now we will see a shift in the financial downturn and the economy will start to rise "out of the tank"........although I think not somehow.
  14. #8
  15. Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Jun 2005
    Posts
    5,964
    Rep Power
    4851
    Ostentatious was good. You finally noticed it and complied, rather than ignoring the advice as you did in the earlier responses.

    I'll bill you later.
    Write no code whose complexity leaves you wondering what the hell you did.
    Politically Incorrect DaWei on Pointers Grumpy on Exceptions
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Posts
    4
    Rep Power
    0
    You're right, it was good.

    Genuinely thank you for the help and advice.
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2009
    Location
    California
    Posts
    1
    Rep Power
    0

    Thumbs up Share and share alike


    Originally Posted by chrandbar
    You're right, it was good.

    Genuinely thank you for the help and advice.
    Now that you have it working, would you mind sharing the entire program with the forum? It would be good to have in case something similar is needed by others.

    Also, I'm curious as to which compiler you're using. Haven't seen plain C code in a while.

    Thanks.
  20. #11
  21. Contributing User

    Join Date
    Aug 2003
    Location
    UK
    Posts
    5,073
    Rep Power
    1802
    Originally Posted by Palmero
    Now that you have it working, would you mind sharing the entire program with the forum?
    Got the same assignment did you? ;)

IMN logo majestic logo threadwatch logo seochat tools logo