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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <stdio.h>
#include <math.h>
#define false 0 //I have to define it, bool doesn't work for Dev-C
#define true 1
int main()
{
int d, m, year, x = 28, date, daysinFeb = 28;
char more;
{
do
{
printf("\n\t\t\tInput date (MM/DD/YYYY): ");
scanf ("%d/%d/%d", &m, &d, &year);
{
if (year % 4 == 0 && !(year % 100 == 0 && year % 400 != 0))
{
if(!checkDate(m,d,year,x))
printf("\n\t\t\tInput mm/dd/yy is wrong!", m,d,year); //everything else works, but it won't just print this.
//It prints "Input is wrong" and "There are x days past". I just need to have it print "Input is wrong" when the date is wrong.
}
}
switch (m)
{
case 1:
date = (d);
break;
case 2:
date = (31 + d);
break;
case 3:
date = (31 + x + d);
break;
case 4:
date = ((2 * 31) + x + d);
break;
case 5:
date = ((2 * 31) + 30 + x + d);
break;
case 6:
date = ((3 * 31) + 30 + x + d);
break;
case 7:
date = ((3 * 31) + (2 * 30) + x + d);
break;
case 8:
date = ((4 * 31) + (2 * 30) + x + d);
break;
case 9:
date = ((5 * 31) + (2 * 30) + x + d);
break;
case 10:
date = ((5 * 31) + (3 * 30) + x + d);
break;
case 11:
date = ((6 * 31) + (3 * 30) + x + d);
break;
case 12:
date = ((6 * 31) + (4 * 30) + x + d);
break;
}
printf("\n\t\t\tThere are %d days past in the year", date);
printf ("\n\t\t\tDo more (Y/N) ? ");
scanf ("%s", &more);
} while (more == 'y' || more == 'Y');
}
}
checkDate(int month, int day, int year, int daysInFeb)
{
int daysinMonth;
if(year <= 0)
return false;
if(month < 1 || month > 12)
return false;
if(month == 2 && day > daysInFeb)
return false;
else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12)
daysinMonth = 31;
else if(month == 4 || month == 6 || month == 9 || month == 11)
daysinMonth = 30;
if(day > daysinMonth)
return false;
else
return true;
}
|