Your program will first put the correct data into 12 struct month objects. Here
ID: 3626252 • Letter: Y
Question
Your program will first put the correct data into 12 struct month objects. Here is the definition you must use for a struct month.struct month {
char nameEng[10];
char nameSpan[11];
int order;
int numDays;
};
You will need to use strcpy to put the strings into nameEng and nameSpan.
Then you will prompt the user for a month and a day.
Then you will search the 12 struct month objects looking for the user's month and give the user an appropriate reply. See below.
Please spell the English months correctly!
January, February, March, April, May, June, July, August, September, October, November, December.
Please spell the Spanish months correctly!
enero, febrero, marzo, abril, mayo, junio, julio, agosto, septiembre, octubre, noviembre, diciembre.
Here is the start of your main function:
int main() {
char mon[20];
int day;
struct month months[12];
initStruct(months); // puts data into the 12 struct month objects
// prompt the user for month and day and store in mon and day
replyToUser( months, mon, day );
return 0;
}
The initStruct function will put appropriate values inside months[]. For example the first element of months should be initialized so that it contains members:
"January"
"enero"
1
31
The second element of months should be initialized to:
"February"
"febrero"
2
28
...
The replyToUser function will go through the array of the structs to try to find a match in English or Spanish to what the user entered.
If it is not found, tell the user you don't know that month and return -1.
If it is found, make sure the day that the user specified is legal. For example, February 29 is not legal (in our program). Of course, neither is February -1, 0, 30, 31, 32, ...
If the day is not legal, tell the user. In the following example, the user entered February 20. Use this format:
2/30 is not a legal date
and then return -1.
If the day is legal, then return which day of the year it is. That is a number in the range (1 - 365) For example, if the user enters
abril 20
Then return 110
because 31 (January) + 28 (February) + 31 (March) + 20 = 110
This function is the ONLY function that prints.
My output-- Each time you run your program, you get to enter one month and one day. I ran my program several times. Here are the outputs:
Please enter the month name in English or Spanish. January
Please enter the day (1-31) 20
That is day #20 in the year.
Please enter the month name in English or Spanish. abril
Please enter the day (1-31) 31
There are 30 days in that month.
So you cannot use the date 4/31.
Please enter the month name in English or Spanish. May
Please enter the day (1-31) 2
That is day #122 in the year.
Please enter the month name in English or Spanish. Febuary
Please enter the day (1-31) 5
I did not find a month by the name Febuary in English or in Spanish.
Please enter the month name in English or Spanish. myo
Please enter the day (1-31) 14
I did not find a month by the name myo in English or in Spanish.
Please enter the month name in English or Spanish. diciembre
Please enter the day (1-31) 31
That is day #365 in the year.
Please enter the month name in English or Spanish. September
Please enter the day (1-31) 31
There are 30 days in that month.
So you cannot use the date 9/31.
Please enter the month name in English or Spanish. June
Please enter the day (1-31) 0
0 is less than 1.
So you cannot use the date 6/0.
Please enter the month name in English or Spanish. November
Please enter the day (1-31) 17
That is day #321 in the year.
Explanation / Answer
/* Hope this will help you */ #include #include struct month { char nameEng[10]; char nameSpan[11]; int order; int numDays; }; char nameE[][10] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; char nameS[][11] = {"enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre"}; int ndays[12] = { 31,28,31,30,31,30,31,31,30,31,30,31}; int initStruct(struct month m[12]) { int i; for(i=0;i months[i].numDays) { printf("This date %d/%d doesn't exists",i+1,day); }else { for(j=0;jRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.