Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct month{
char nameEng[10];
char nameSpan[11];
int order;
int numDays;
};
// put your function declarations here
int findDayCount(struct month *m, char *user, int day);
void initStruct(struct month month[]);
int main(void) {
// declare other variables here
struct month months[12];
initStruct(months);
int enter_day;
char enter_month[11];
int x;
// lots of your code here
printf("What month: "); //asking for month
fflush(stdout);
scanf("%s", enter_month);
printf("What day: "); //asking for day
fflush(stdout);
scanf("%d", &enter_day);
x = findDayCount(months, enter_month, enter_day);
printf("That day is the #%d in the entire year out 365 days.", x);
return EXIT_SUCCESS;
}
int findDayCount(struct month *m, char *user, int day){
int total=0;
int i;
// Checking to see if the enter_month is == to english or spanish
for(i = 0; i < 12; i++)
{
if(strcasecmp(user, m[i].nameEng) == 0)
{
strcpy(user, m[i].nameEng);
printf("You entered in the month, %s, in english.\n", user);
fflush(stdout);
}
else if(strcasecmp(user, m[i].nameSpan) == 0)
{
strcpy(user, m[i].nameSpan);
printf("You enterd in the mont, %s, in spanish.\n", user);
fflush(stdout);
}
else
{
printf("That month cannot be found either in english or in spanish, please check your spelling.\n");
fflush(stdout);
return -1;
}
}
// Checking to see if the days are in the right range.
if(day > 31 || day < 1)
{
printf("There are no %d days in that month.\n", day);
fflush(stdout);
}
else if(day > 28 && (user == "february" || user == "febrero"))
{
printf("There are no %d in the month, %s. There is only 28.\n", day, user);
fflush(stdout);
}
else if(day > 30 && (user == "april" || user == "june" || user == "august" || user == "september" || user == "november"))
{
printf("There are no %d in the month, %s. There are only 30 days.", day, user);
fflush(stdout);
}
else if(day < 1)
{
printf("There are is no zero day. Did you type in the day correctly?\n");
fflush(stdout);
}
total = m[i].numDays + day;
return(total);
}
void initStruct(struct month month[]){
int monthLeng[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
strcpy(month[0].nameEng, "January");
strcpy(month[0].nameSpan, "Enero");
month[0].numDays = monthLeng[0];
month[0].order = 1;
strcpy(month[1].nameEng, "February");
strcpy(month[2].nameSpan, "Febrero");
month[1].numDays = monthLeng[1];
month[1].order = 2;
strcpy(month[2].nameEng, "March");
strcpy(month[2].nameSpan, "Marzo");
month[2].numDays = monthLeng[2];
month[2].order = 3;
strcpy(month[3].nameEng, "April");
strcpy(month[3].nameSpan, "Abril");
month[3].numDays = monthLeng[3];
month[3].order = 4;
strcpy(month[4].nameEng, "May");
strcpy(month[4].nameSpan, "Mayo");
month[4].numDays = monthLeng[4];
month[4].order = 5;
strcpy(month[5].nameEng, "June");
strcpy(month[5].nameSpan, "Junio");
month[5].numDays = monthLeng[5];
month[5].order = 6;
strcpy(month[6].nameEng, "July");
strcpy(month[6].nameSpan, "Julio");
month[6].numDays = monthLeng[6];
month[6].order = 7;
strcpy(month[7].nameEng, "August");
strcpy(month[7].nameSpan, "Agosto");
month[7].numDays = monthLeng[7];
month[7].order = 8;
strcpy(month[8].nameEng, "September");
strcpy(month[8].nameSpan, "Septiembre");
month[8].numDays = monthLeng[8];
month[8].order = 9;
strcpy(month[9].nameEng, "Octber");
strcpy(month[9].nameSpan, "Octubre");
month[9].numDays = monthLeng[9];
month[9].order = 10;
strcpy(month[10].nameEng, "November");
strcpy(month[10].nameSpan, "Noviembre");
month[10].numDays = monthLeng[10];
month[10].order = 11;
strcpy(month[11].nameEng, "December");
strcpy(month[11].nameSpan, "Diciembre");
month[11].numDays = monthLeng[11];
month[11].order = 12;
}