+2 votes
162 views

Write enumerated types that supports dates—such as december 12. Then add a function that produces a next day. So nextday(date) of december 12 is december 13. Also write a function printdate(date) that prints a date legibly.The function can assume that February has 28 days and it most know how many days are in each month. Use a struct with two members; one is the month and the second is the day of the month—an int (or short).

typedef enum month{ jan, feb, …} month; typedef struct date{ month m; int d} date;

Then print out the date January 1 and print the next day Jan 2.

Do this for the following dates: February 28, March 14, October 31, and December 31.

| 162 views
We shall answer your question soon.
( Delay is expected due some local site business works so, plz bear with us. )

Thanks for being active on our community site.

## 1 Answer

+2 votes

C For Everyone - Structured Programming Week 2

``````#include<stdio.h>

int da=0;
int mo=0;

typedef enum month{January,February,March,April,May,June,July,August,September,October,November,December} month;

void printdate()
{
if(mo==2)
printf("March %d\n",da);
else if(mo==10)
printf("November %d\n",da);
else if(mo==0)
printf("January %d\n",da);

}
typedef struct date{
month m;
int d;
} date;

void nextday(date dat)
{
if(dat.m==1 && dat.d==28)
{
da=1;
mo=(dat.m+1);

}
else if(dat.m==2 && dat.d==14)
{
da=15;
mo=2;
}
else if(dat.m==9 && dat.d==31)
{
da=1;
mo=10;
}
else if(dat.m==11 && dat.d==31)
{
da=1;
mo=0;
}

}

int main(){

date dates;

dates.m=February;
dates.d=28;
nextday(dates);
printdate();

dates.m=March;
dates.d=14;
nextday(dates);
printdate();

dates.m=October;
dates.d=31;
nextday(dates);
printdate();

dates.m=December;
dates.d=31;
nextday(dates);
printdate();

}``````
by (170 points)
You are the best Man... Thanks dear!
You saved my time bro!

+1 vote
0 answers
+1 vote
1 answer
+3 votes
0 answers
+2 votes
0 answers
+2 votes
2 answers
+2 votes
1 answer
+2 votes
1 answer
+2 votes
1 answer
+3 votes
1 answer
+2 votes
1 answer