#include <stdio.h> #include <time.h> #include <iostream> #include <string.h> int main() { struct tm*timeptr; time_t secsnow; char s1[30],s2[30],s3[30]; int xz,day,hours; printf("你是谁?请选择--输入序号/n"); printf("1.wangzi 2.wangyu 3.xiaoyu 4.me 5.other/n"); scanf("%d",&xz); switch(xz) { case 1:strcpy(s1,"wangzi 同学!"); break; case 2:strcpy(s1,"wangyu 老师!"); break; case 3:strcpy(s1,"xiaoyu 同学!"); break; case 4:strcpy(s1,"me 同学!"); break; case 5:strcpy(s1," other"); break; } //13行到21行,为用户输入提示序号 用switch case语句判断选择 time(&secsnow); timeptr=localtime(&secsnow); day=timeptr->tm_wday; if(day==6) { strcpy(s2,"Happy Saturday!"); } else if(day==0) { strcpy(s2,"Happy Sunday!"); } else if(day==1) { strcpy(s2,"Happy Monday!"); } else if(day==2) { strcpy(s2,"Happy Tuesday!"); } else if(day==3) { strcpy(s2,"Happy Wednesday!"); } else if(day==4) { strcpy(s2,"Happy Thursday!"); } else if(day==5) { strcpy(s2,"Happy Friday!"); } else strcpy(s2," "); //25行到55行为,判断星期,输出相应的问候语 hours=timeptr->tm_hour; if(hours>=4&&hours<=10) strcpy(s3," 早 上 好!"); else if(hours>=11&&hours<=16) strcpy(s3," 下 午 好!"); else if(hours>=17&&hours<=22) strcpy(s3," 晚 上 好!"); else strcpy(s3,""); //57到64行,为判断时间,输出相应的问候语 printf("%s %s/n%s/n",s1,s3,s2); //输出 指针数组 printf("/n"); system("pause"); }