Commit be0f0170 by Gürcan Güleç

Fixing calendar.c

parent 339b27f6
Showing with 17 additions and 3 deletions
...@@ -17,7 +17,15 @@ int main() ...@@ -17,7 +17,15 @@ int main()
int leap = 0; int leap = 0;
int m1[7] = {1, 3, 5, 7, 8, 10, 12}; int m1[7] = {1, 3, 5, 7, 8, 10, 12};
printf("Enter a date(DDMMYYY): ");
scanf("%d", &date); scanf("%d", &date);
if(date < 0)
{
printf("Date cannot be minus: ");
scanf("%d", &date);
}
// finding the year // finding the year
int year = date % 10000; int year = date % 10000;
...@@ -31,8 +39,14 @@ int main() ...@@ -31,8 +39,14 @@ int main()
printf("Month = %d\n",month); printf("Month = %d\n",month);
printf("Year = %d\n",year); printf("Year = %d\n",year);
if(date <= 0)
{
printf("Date not valid\n");
return 0;
}
// month cannot be bigger than 12 // month cannot be bigger than 12
if(month > 12) if(month > 12 || month <= 0)
{ {
printf("Date not valid\n"); printf("Date not valid\n");
return 0; return 0;
...@@ -89,7 +103,7 @@ int main() ...@@ -89,7 +103,7 @@ int main()
{ {
if(leap == 1) if(leap == 1)
{ {
if(day != 29) if(day > 29)
{ {
printf("Date not valid\n"); printf("Date not valid\n");
return 0; return 0;
...@@ -97,7 +111,7 @@ int main() ...@@ -97,7 +111,7 @@ int main()
} }
else else
{ {
if(day != 28) if(day > 28)
{ {
printf("Date not valid\n"); printf("Date not valid\n");
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment