Another Calendar/Birthday Question-Please help- SORRY!

This is a discussion on Another Calendar/Birthday Question-Please help- SORRY! within the C Programming forums, part of the General Programming Boards category; I am sorry to repost a question about a calendar, because i've done some searching and found similar problems. The ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    3

    Another Calendar/Birthday Question-Please help- SORRY!

    I am sorry to repost a question about a calendar, because i've done some searching and found similar problems.

    The program shoudl function like this:
    1 - User enters the date of birth mm , then dd, then yy
    2 - program gives the day of the week for that given date, with respect to leap years.

    This is what i have so far. When I run the program and give the date, it just kicks some numbers back to me. I'm fairly new to programming. PLEASE HELP!

    Thanks,



    /* Write a program that, given a person's birthdate (or any other date in the
    gregorian calendar) will display the day of the week that the person was born.
    */

    #include <stdio.h>
    /* Prototype Declarations */
    void get_data(int *year, int *month, int *day);
    int calc_day(int year, int month, int day);
    void print_results(int total);


    int main()
    {
    /* Local Definitons */
    int year;
    int month;
    int day;
    int total;

    get_data(&year, &month, &day);
    total = calc_day(year, month, day);
    print_results(total);

    return 0;
    }

    void get_data(int *year, int *month, int *day)
    {

    printf("\nEnter the Month of the Person's Birthdate:\n");
    scanf("%d", &month);
    printf("\nEnter the Day of the Person's Birthdate:\n");
    scanf("%d", &day);
    printf("\nEnter the Year of the Person's Birthdate:\n");
    scanf("%d", &year);
    printf("\nHere is the date entered: %d/%d/%d\n", month, day, year);
    return;
    }

    int calc_day(int year, int month, int day)
    {
    /* Local Definitons */
    int dayofdec31;
    int total;
    /* Calculate Day of December 31 */
    dayofdec31 = ((((year - 1)*365) + ((year - 1)/100) + ((year - 1)/400)) % 7);

    total = 0;
    switch (month)
    {
    case 12 : total = total + 30;
    case 11 : total = total + 31;
    case 10 : total = total + 30;
    case 9 : total = total + 31;
    case 8 : total = total + 30;
    case 7 : total = total + 31;
    case 6 : total = total + 30;
    case 5 : total = total + 31;
    case 4 : total = total + 30;
    case 3 : total = total + 31;
    case 2 : total = total + 28;
    case 1 : total = total + 0;


    }
    /* Calculate Leap year */
    if ((!(year % 4) && (year % 100) ) || !(year % 400))
    {
    if (month > 2)
    {
    total = (total + day + 1);
    }
    }
    else
    {
    total = (total + day);
    }

    return ((total + dayofdec31)%7);
    }


    void print_results(int total)
    {
    /* Local Definitons */
    int days;

    switch(days)
    {
    case 0 : printf("Sunday\n");
    break;
    case 1 : printf("Monday\n");
    break;
    case 2 : printf("Tuesday\n");
    break;
    case 3 : printf("Wednesday\n");
    break;
    case 4 : printf("Thursday\n");
    break;
    case 5 : printf("Friday\n");
    break;
    case 6 : printf("Saturday\n");
    break;
    }
    printf("\nThe Person's Birthday Is On: %d\n", days);

    getch();
    return;

    }

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Using [code] [/code] tags makes posted code easier to read.
    Code:
    void get_data(int *year, int *month, int *day)
    {
    
        printf("\nEnter the Month of the Person's Birthdate:\n");
        scanf("%d", &month); /* month is a pointer, remove the '&' */
        printf("\nEnter the Day of the Person's Birthdate:\n");
        scanf("%d", &day);   /* day is a pointer, remove the '&' */
        printf("\nEnter the Year of the Person's Birthdate:\n");
        scanf("%d", &year);  /* year is a pointer, remove the '&' */
        printf("\nHere is the date entered: %d/%d/%d\n",  *month, *day, *year);
        return;
    }
    Code:
    void print_results(int total)
    {
        /* Local Definitons */
        int days;
    
        switch ( days ) /* Symbol 'days' not initialized */
        {
        case 0 : printf("Sunday\n");
            break;
        case 1 : printf("Monday\n");
            break;
        case 2 : printf("Tuesday\n");
            break;
        case 3 : printf("Wednesday\n");
            break;
        case 4 : printf("Thursday\n");
            break;
        case 5 : printf("Friday\n");
            break;
        case 6 : printf("Saturday\n");
            break;
        }
        printf("\nThe Person's Birthday Is On: %d\n", days);
    
        getch();
        return;
    
    } /* Symbol 'total' not referenced */
    There are still problems with the calculations, I didn't look into that.
    Code:
    Enter the Month of the Person's Birthdate:
    4
    
    Enter the Day of the Person's Birthdate:
    22
    
    Enter the Year of the Person's Birthdate:
    2003
    
    Here is the date entered: 4/22/2003
    Wednesday
    
    The Person's Birthday Is On: 3
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    How did you get those results? I made the same changes you made to the program, and I got pretty much the same results as before...

    thanks for helping

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Oops. I had used the following for the sample run.
    Code:
    void print_results(int total)
    {
        /* Local Definitons */
        int days = total;
    
        switch ( days )
    It didn't make sense to have both the "not initialized" and "not referenced" comments in there along with my guess at your intent.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  5. #5
    Registered User
    Join Date
    Apr 2003
    Posts
    3
    You're a lifesaver. Sometimes when you're new to this, if you stare at the screen too long, you can overlook things like that.
    Thanks very much for your help.

    I still have to figure out why it's calculating the days incorrectly, but that could be just a typo on my part.
    Thanks again,
    Ryan
    Last edited by dauz; 04-22-2003 at 01:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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