Writing a program to make a calendar
So I need to write a program that makes a calendar. Basically, if I input a year, the output is supposed to be a calendar for the whole year (12 months).
The program is also supposed to ask the user if the user wants to continue, and if the user answers yes, then it will print the calendar for another year.
I don't really know where to start on this, except that I know I need to use another program that I wrote for what day any random date in time is (enter 12-20-1255 and it gives you the day of the week). I posted that program below. Could someone help me get started on converting this program to make a calendar?
Code:
#include <stdio.h>
int main()
{
int month, day, year, prevyear, numdays;
printf("Please enter a date for month-day-year: ");
scanf("%d-%d-%d", &month, &day, &year);
prevyear = ((year - 1) * 365 + ((year - 1)/4) - ((year - 1)/100) + ((year - 1)/400)) % 7;
numdays = 0;
switch(month)
{
case 12:
numdays += 30;
break;
case 11:
numdays += 31;
break;
case 10:
numdays += 30;
break;
case 9:
numdays += 31;
break;
case 8:
numdays += 31;
break;
case 7:
numdays += 30;
break;
case 6:
numdays += 31;
break;
case 5:
numdays += 30;
break;
case 4:
numdays += 31;
break;
case 3:
if ((!(year % 4) && (year % 100)) || ! (year % 400))
numdays += 29;
else numdays += 28;
break;
case 2:
numdays += 31;
break;
}
switch(day)
{
case 6:
printf("The day was Saturday");
break;
case 5:
printf("The day was Friday");
break;
case 4:
printf("The day was Thursday");
break;
case 3:
printf("The day was Wedensday");
break;
case 2:
printf("The day was Tuesday");
break;
case 1:
printf("The day was Monday");
break;
case 0:
printf("The day was Sunday");
break;
}
return(0);
}
source code...... it works fine...
this code works fine
small problem is the months r printed in order
not by tabs
hope u understand
so to completely view ouput
rediect output
Code:
#include<stdio.h>
#define p printf
main()
{
int d,y,no_lp,n,i=1,j,nod[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
p("enter yr:");
scanf("%d",&y);
no_lp=(y-2001)/4;
/*no of leap yrs betwen 2001 and the yr*/
d=(y-2001+no_lp)%7;
/*the day of 1st month*/
n=d;
if(y%4==0)
nod[2]=29;
for(j=1;j<=12;j++)
{
p("\nm t w t f s s\n");
while(d--!=0)
p(" ");
while(i<=nod[j])
{
if(i<10)
{p("%d ",i++);}/*formattng for dates with 2 digits*/
else{p("%d ",i++);}
n++;
if(n==7)
{n=0;p("\n");}
}
d=n;i=1;/*n will be the 1st day of next month*/
}
getch();
}