I keep getting the same day of the week no matter what the user enters. #include
ID: 3644477 • Letter: I
Question
I keep getting the same day of the week no matter what the user enters.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
// Prototype Declarations
getData(int *year, int *month, int *day);
int dayOfWeek (int year, int month, int day);
void print_results(int total);
int main()
{
// Local Definitons
int year;
int month;
int day;
int total;
getData(&year, &month, &day);
total = dayOfWeek (year, month, day);
print_results(total);
return 0;
}
getData(int *year, int *month, int *day)
{
printf(" Enter the Month of the Person's Birthdate: ");
scanf("%d", &month);
printf(" Enter the Day of the Person's Birthdate: ");
scanf("%d", &day);
printf(" Enter the Year of the Person's Birthdate: ");
scanf("%d", &year);
printf(" Here is the date entered: %d/%d/%d ", month, day, year);
return;
}
int dayOfWeek (int year, int month, int day)
{
// Local Definitons
int dec31;
int total;
// Calculate the Day of December 31
dec31 = ((((year - 1)*365) + ((year - 1)/4) - ((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 + 31;
case 7 : total = total + 30;
case 6 : total = total + 30;
case 5 : total = total + 30;
case 4 : total = total + 31;
case 3 : total = total + 28;
case 2 : total = total + 31;
case 1 : total = total + 30;
}
// Leap Year Calculation
if ((!(year % 4) && (year % 100) ) || !(year % 400))
{
if (month > 2)
{
total = (total + day + 1);
}
}
else
{
total = (total + day);
}
return ((total + dec31)%7);
}
void print_results(int total)
{
// Local Definitons
int days = total;
switch ( days )
{
case 0 : printf("Sunday ");
break;
case 1 : printf("Monday ");
break;
case 2 : printf("Tuesday ");
break;
case 3 : printf("Wednesday ");
break;
case 4 : printf("Thursday ");
break;
case 5 : printf("Friday ");
break;
case 6 : printf("Saturday ");
break;
}
printf(" The Person's Birthday Is On: %d ", days);
return;
}