#include <stdio.h> #include <string.h> #include <stdlib.h> #include "lovedays.h" #define Z_OK 1 #define Z_ERR 0 ULONG g_ulRet = 0; //SYSTEMTIME * g_pstSysTime;/* 在Public.c中定义当的前系统时间的全局变量 */ extern char * week[7]; ULONG g_ulYear = 0; ULONG g_ulMonth = 0; ULONG g_ulDay = 0; void InitTime() { g_ulYear = (ULONG)g_pstSysTime->wYear; g_ulMonth = (ULONG)g_pstSysTime->wMonth; g_ulDay = (ULONG)g_pstSysTime->wDay; } void LOVEDAYS_main() { char ch = 0; int chioce = 0; int flag = 1; system("cls"); ShowCurTime(); LoveDaysVision(); InitTime(); showDate(g_ulYear,g_ulMonth,g_ulDay); while( flag ) { printf( "\n\n\n" ); //ShowCurTime(); printf("请老婆大人选择功能:(输入数字1~3)\n"); printf("1.计算我们的恋爱天数 2.退出\n"); //scanf("%d",&chioce); ch = getch(); chioce = atoi(&ch); system("cls"); ShowCurTime(); LoveDaysVision(); switch(chioce) { case 1: showjinianri();break; case 2: break; case 3: printf("谢谢老婆大人使用,以后等老公给你做更好的给你玩哈^_^!!\n"); flag = 0; } } } /* 将输入的时间写入全局变量中 */ ULONG inPutDate(ULONG * ul_pYear,ULONG ul_pMonth,ULONG ul_pDay) { printf("*************************************************\n"); printf("请分别输入年月日\n"); printf("[年]:"); //scanf("%d",&g_ulYear); INPUT(ul_pYear); printf("[月]:"); //scanf("%d",&g_ulMonth); INPUT(ul_pMonth); printf("[日]:"); //scanf("%d",&g_ulDay); INPUT(ul_pDay); if ( 0 == g_ulRet ) { //printf( "return Z_ERR\n"); return Z_ERR; } else { //printf( "return Z_OK\n"); return Z_OK; } } void showDate( int yy,int mm,int dd ) { int d = 0; int t = 0; if(youxiao(yy,mm,dd)) { printf("这是一年中的第%d天!\n",dijitian(yy,mm,dd)); t = xingqiji(yy,mm,dd); printf("%d年%d月%d日是星期%s\n",yy,mm,dd,week[t]); d = lovedays(yy,mm,dd); if(d != 0) printf("这是我们恋爱第%d天纪念日!!\n",d); } printf("*************************************************\n"); } void showjinianri() { // printf("%d",youxiao(yy,mm,dd)); /*输入时间*/ if ( Z_ERR == inPutDate(&g_ulYear,&g_ulMonth,&g_ulDay)) { //printf( "<q> to quit,other to continue!!!\n" ); return; } showDate(g_ulYear,g_ulMonth,g_ulDay); } int youxiao(int y,int m,int d) { int flag=0; //printf("(你输入的日期正在验证中....)\n"); if(y<1) { printf("(输入的年份有误!)\n"); } else if(m>12||m<1) { printf("(输入的月份有误!)\n"); } else if(m==2) { if(d>(28+leapyear(y))||d<1) printf("(输入的日数有误!)\n"); else { flag = 1; printf("(恭喜你输入的日期通过了验证!)\n"); } } else if(m==1||m==3||m==5||m==7||m==8||m==10||m==12) { if(d<0||d>31) printf("输入的日数有误!\n"); else { flag = 1; printf(" *^ ^* \n"); } } else if(m==4||m==6||m==9||m==11) { if(d<0||d>30) printf("输入的日数有误!\n"); else { flag = 1; printf("(恭喜你输入的日期通过了验证!)\n"); } } return flag; } int leapyear(int yyy) { return ((yyy%4==0)&&(yyy%100!=0)||(yyy%400==0)); } int dijitian(int year,int mon,int day) { /*这个也可以,也是一种算法 int sum = 0; switch(y) { case 12:sum += 30; case 11:sum += 31; case 10:sum += 30; case 9: sum += 31; case 8: sum += 31; case 7: sum += 30; case 6: sum += 31; case 5: sum += 30; case 4: sum += 31; case 3: sum += 28+isyunnian(x); case 2: sum += 31; case 1: sum += z; } return sum;*/ int today = day; int m; for(m=0;m<mon-1;m++) if(leapyear(year))today += day1[m]; else today +=day2[m]; return today; } int xingqiji(int x,int y,int z) { long int days = 0;//前x-1年的总天数 int n; int i; long int DAYS; if(x==1) DAYS=dijitian(x,y,z); else for(i = 2;i<=x;i++) days += (leapyear(i-1)?366:365); // days1 = dijitian(x,y,z); // days2 = ((leapyear(1)?366:365);//2年 // days3 = ((leapyear(2)?366:355)+(leapyear(1)?366:365) DAYS = days + dijitian(x,y,z); printf("你输入的日期距公元元年%d天!\n",DAYS); n = ((int)DAYS%7); return n; } int lovedays(int x,int y,int z) { int DAYS2 = 0; int days = 18;//前x-1年的总天数 int i; //char week[7][5] = {"日","一","二","三","四","五","六"}; if(x<=2009 && y <=12 && z<13) { printf("那时我们还没有开始恋爱!\n",x,y,z); } else if(x == 2009&&y==12&&z==13) { printf("这是我们的恋爱纪念日,我会永远记住的!~\n"); } else if(x == 2009 && y == 12 && z >13) { printf("亲爱的,我们成功地走过%d天了,恋爱快乐,再接再厉哦!!\n",z-13); } else if(x > 2009) { for(i = 2011;i<=x;i++) days += (leapyear(i-1)?366:365); DAYS2 = days + dijitian(x,y,z); printf("亲爱的,我们成功地走过%d天了,恋爱快乐,再接再厉哦!!\n",DAYS2); } return DAYS2; }