c - How do I handle a calender without a massive 12x12 switch statement? -
i'll heading tutoring tomorrow, i'd see if can explanation here. tried ask friend class, explanation didn't make sense.
i'm supposed take user's input in form of structure holds day, month, , year.
here's have right now:
enum month { jan = 1, feb, mar, apr, may, june, jul, aug, sept, oct, nov, dec }; struct date_t { unsigned short month; unsigned short day; unsigned short year; }; int main(void) { date_t date; /*allocates space 3 unsigned shorts, date*/ printf("please enter month integer: \n"); scanf("%hu"); printf("please enter day integer: \n"); scanf("%hu"); printf("please enter year integer: \n"); scanf("%hu"); return 0; }
so, here's issue.
i write absolutely massive 12x12 (144 options) switch statement every single case of month + zodiac sign combination, that's insanity. don't know here.
the idea if user entered:
8 (month) 28 (day) 12 (year)
my program should output:
august 28th, 2012, virgo
the main issue haven't learned way store strings variable yet. that's past we've done.
so make 1 switch statement 12 cases (one each month) , give each 1 different "printf" statement starting ("month %d, %d", date.day, date.year)
but how do zodiac sign? also, that's 12 cases, feels little ridiculous.
my teacher suggested converting julian dates, , understand how, seems i'd need complicated loop switch statement or bunch of if/elses in there.
what in world doing wrong? simpler solution?
edit:
i managed solve 2/3 of problem. i'm running different one.
i need deal leap years (whatever means) , find sign. gah.
edit 2: figured out! wish show code without making post absolutely absurdly long. works though! happy! need make menu system it. ;-;
i think thinking have make print statement prints whole line @ once, can have multiple print statements, each prints part of line.
since learning exercise, don't want give away, realize print answer this:
printf("august "); printf("28th, "); printf("2012, "); printf("virgo"); printf("\n");
Comments
Post a Comment