Results 1 to 2 of 2

Thread: [RESOLVED] Help calculating easter date...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Resolved [RESOLVED] Help calculating easter date...

    Heyy, what's up?

    I need some help doing this (it's an assingment, by the way)...

    This is my code:

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    void main(void){
        int d, m, y, o; //day, month year, option
        int c,g,k,i,j,l; //variables needed to calculate the date..
    tryagain:
        printf("Write a year to calculate it's easter date:  ", a);
        scanf("%d", &a);
    
        if (a < 1000 || a > 9999){
                printf("That year is not valid.\n");
                printf("Try again (0 = no/1 = yes): ", o);
                scanf("%d", &o);
                if (o == 1) {
                        system("CLS");
                        goto tryagain;
                }
                else {
                    printf("Bye Bye...\n");
                }
        }
        else if(a>=1000 && a < 10000){
                //Calculation of the easter date...
                c = y/100;
                g = y % 19;
                k = (c - 17)/25;
                i = (c - c/4 - (c - k)/3 + 19*g + 15) % 30;
                i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - g)/11));
                j = (c + c/4 + i + 2 - c + c/4) % 7;
                l = i - j;
                m = 3 + (l + 40)/44;
                d = l + 28 - 31*(m/4);
    
                m = 3+(l+40)/44;
                d=m+28-31*(m/4);
                printf("\n==================================\n");
                printf("La fecha del Easter es: %d/%d/%d.\n", d, m, c);
                printf("==================================\n\n");
        }
        printf("Go again (0 = no/1 = yes): ", o);
        scanf("%d", &o);
        if (o == 1) {
            system("CLS");
            goto tryagain;
            }
        else {
            printf("Bye...\n");
            }
        system("PAUSE");
        return 0;
    }
    The code prints the same dates... This is based on Oudin's algorithm.

    Thanks in advance!
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [RESOLVED] Help calculating easter date...

    Got it working... This is the code:

    vb.net Code:
    1. #include <stdlib.h>
    2. #include <stdio.h>
    3.  
    4. int main(int argc, char *argv[]){
    5.     int d, m, y, o; //day, month year, option
    6.     int c,g,k,i,j,l; //variables needed to calculate the date..
    7. tryagain:
    8.     printf("Write a year to calculate it's easter date:  ", a);
    9.     scanf("%d", &a);
    10.  
    11.     if (a < 1000 || a > 9999){
    12.             printf("That year is not valid.\n");
    13.             printf("Try again (0 = no/1 = yes): ", o);
    14.             scanf("%d", &o);
    15.             if (o == 1) {
    16.                     system("CLS");
    17.                     goto tryagain;
    18.             }
    19.             else {
    20.                 printf("Bye Bye...\n");
    21.             }
    22.     }
    23.     else if(a>=1000 && a < 10000){
    24.             //Calculation of the easter date...
    25.             c = y/100;
    26.             g = y % 19;
    27.             k = (c - 17)/25;
    28.             i = (c - c/4 - (c - k)/3 + 19*g + 15) % 30;
    29.             i = i - (i/28)*(1 - (i/28)*(29/(i + 1))*((21 - g)/11));
    30.             j = (c + c/4 + i + 2 - c + c/4) % 7;
    31.             l = i - j;
    32.             m = 3 + (l + 40)/44;
    33.             d = l + 28 - 31*(m/4);
    34.             printf("\n==================================\n");
    35.             printf("La fecha del Easter es: %d/%d/%d.\n", d, m, c);
    36.             printf("==================================\n\n");
    37.     }
    38.     printf("Go again (0 = no/1 = yes): ", o);
    39.     scanf("%d", &o);
    40.     if (o == 1) {
    41.         system("CLS");
    42.         goto tryagain;
    43.         }
    44.     else {
    45.         printf("Bye...\n");
    46.         }
    47.     system("PAUSE");
    48.     return 0;
    49. }
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width