Code:
#include <stdio.h>
// Sets a multidimentional array for months
char cmonth[ 12 ][ 10 ] = { "January" , "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
// Sets inital conditions for variables
int z=0, i=0, c=0, p, days;
int start=1, month, year=2001;
// Sets inital constants for days
int cday[ 12 ] = { 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 };
// Declares functions
void checkyear(), checkvalues(), pause();
int caldays(), leapyear();
int main(void)
{
printf("Enter Date to Start At (UK Format: dd/mm/yyyy):");
scanf("%d/%d/%d", &start, &month, &year);
i = (month - 1); // Assign starting month
checkyear();
checkvalues();
while(1) // Infinate Loop for Years
{
while (i < 12) // Loop for Months
{
days = caldays(i); // Assign number of days for month
for (z = start; z <= days; z++)
{
printf("\r%2.0d %9s %d ", z, cmonth[ i ], year);
pause();
}
i++ ; // Increment Month
start=1; // Reset to begining of month
}
i = 0; // Resets months
z = 0; // Resets days
year++; // Increment year
}
}
int caldays(i)
{
if (i == 1 && leapyear())
{
return 29; // If so, returns days as 29
}
else
{
return cday[i]; // Else, returns days for month i
}
}
int leapyear(void)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) // Tests for leap year
{
return 1; // If so, returns TRUE (1)
}
else
{
return 0; // Else, returns FALSE (0)
}
}
void pause(void)
{
for (p=0; p=10000; p++)
{
;
}
}
void checkyear(void)
{
if (year < 1582)
{
printf("\nThis program follows the Gregorian Calendar, it was first introduced in 1582. The year you have entered is less than 1582. Please enter a new date\n\n");
main();
}
}
void checkvalues(void)
{
if (month < 1 || month > 12 || start < 1 || start > cday[i])
{
printf("\nDate entered is invalid. Please enter a new one\n\n");
main();
}
}
Thanks