Just need a little help guys !

I am sorry to post 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.

Heres my output somehow :

#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;

}



I JUST WANT TO KNOW GUYS , WHAT'S WRONG WITH MY PROGRAM , THE INPUT FOR THE MONTH, DAY , AND YEAR WAS OK , BUT WHEN THE PERSON'S REAL DAY WAS ENTERES , THERE IS SOMEHOW AN ERROR , THE DAY WAD NOT EVEN EXISTED , ONLY NUMBERS APPEARED ..

REALLY NEED A HELP FOR SOMEONE WHO KNOWS C SOURCE .. THANK YOU SO MUCH GUYS
You may want to start by insuring your compiler is generating warnings, and if it is fix all warnings it generates. Most of your problems will probably be fixed if you fix the warnings your compiler should be generating.

main.c||In function ‘get_data’:|
main.c|28|warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int **’ [-Wformat]|
main.c|30|warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int **’ [-Wformat]|
main.c|32|warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int **’ [-Wformat]|
main.c|33|warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘int *’ [-Wformat]|
main.c|33|warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘int *’ [-Wformat]|
main.c|33|warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘int *’ [-Wformat]|
main.c||In function ‘calc_day’:|
main.c|46|warning: switch missing default case [-Wswitch-default]|
main.c||In function ‘print_results’:|
main.c|85|warning: switch missing default case [-Wswitch-default]|
main.c|104|error: implicit declaration of function ‘getch’ [-Wimplicit-function-declaration]|
main.c|80|warning: unused parameter ‘total’ [-Wunused-parameter]|
||=== Build finished: 1 errors, 9 warnings ===|


Also please use code tags when posting code!
Last edited on
Topic archived. No new replies allowed.