'tigrfire' writes:
I'm trying to write a program that will display the following output:
MONTHLY CALENDAR
This program displays a calendar. You need to provide the day of the
week
on which January 1 falls, and indicate whether or not the year is a
leap year.
Enter the code number for the day of the week on which January 1 falls:
0- Sun 1- Mon 2- Tue 3- Wed 4- Thu 5- Fri 6- Sat
Enter day code now (0 - 6): 4
Is the calendar for a leap year? (type 1 for yes, 0 for no): 0
*** CALENDAR ***
January
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
February
Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
.
.
.
(output continues for all 12 months)
I'm not asking for source code necessarily, not that it wouldn't help,
but I'd just like some suggesstions on how to either modify or change
my current code in order to achieve a program that's not just a bunch
of wasted, repetitive code, like it currently is.
Here's what I've written, the problem is, it will only work, obviously,
for when there's no leap year, and January 1 comes on a Sunday. I don't
have a lot of programming experience and pretty much everything you see
here is all I can utilize.
<snip>
For the 'meaty' part of the program, the part that displays the actual
numbers, you want a function that can print 28, 39, 30 or 31 days with a gap
at the beginning of from 0 to 6 days. So I suggest trying to write a
function suggested by the following prototype.
void print_month(int skip, int tot_days); /* 0.6, 28.31*/
This may suggest subsidiary functions, it may not. It kind of depends on
how your mind works.
The header that goes Sun Mon , Sat could be called as the first line of
the above function, it's always the same.
The line that prints the name of the month could be in a two dimensional
array ( a constant) so you merely provide the month number to cause it to be
printed. You could modify print_month so it could print the name of the
month as well. Two dimensional arrays are a bit nasty so do this last.