这几天晚自习在书上看到了一个题目,脑子有点乱,模拟了半天都没出结果,索性就回来写了一下;
果然,像我这种脑子不好的,还是写出来比较好……
#include <stdio.h>
main()
{
int y0,y1,m0,m1,d0,d1;
char answer;
point1://get the information
printf("Please enter your birthday:\n");
printf("Y,M,D");
putchar ('\n');
scanf("%d,%d,%d",&y0,&m0,&d0);//enter the birthday
if (m0>=13||m0<0)
{printf("error!\nPlease enter right date!");
goto point1;
}
printf("Is this your birthday?\n");
printf("Please enter \"Y\" to make sure your birthday! \n");//be sure the birthday
scanf("%s",&answer);
if (answer=='Y'||answer=='y')
;
else goto point1;
main()
{
int y0,y1,m0,m1,d0,d1;
char answer;
point1://get the information
printf("Please enter your birthday:\n");
printf("Y,M,D");
putchar ('\n');
scanf("%d,%d,%d",&y0,&m0,&d0);//enter the birthday
if (m0>=13||m0<0)
{printf("error!\nPlease enter right date!");
goto point1;
}
printf("Is this your birthday?\n");
printf("Please enter \"Y\" to make sure your birthday! \n");//be sure the birthday
scanf("%s",&answer);
if (answer=='Y'||answer=='y')
;
else goto point1;
point2:
printf("Now please enter the date :\n");
printf("Y,M,D");
putchar ('\n');
scanf("%d,%d,%d",&y1,&m1,&d1);//get the date
if (m1>=13||m1<0)
{printf("error!\nPlease enter right date!");
goto point2;
}
/*time to calculate*/
y0=y1-y0;
if ((d1-d0<=0)||(m1-m0<=0))
y0--;
printf("Well your age must be %d ",y0);
m0=m1-m0;
m0*=-1;
d0=d1-d0;
if (d1-d0<=0)
m0--;
d0*=-1;
printf("And you have left %d years,%d mounth,%d days!",y0,m0,d0);
putchar('\n');
/*time to judje*/
printf("Is it right?\n");
scanf("%s",&answer);
if (answer=='y'||answer=='Y')
printf("(ノOVO)ノ");//(ノOVO)ノ
else {printf(":p\n");
printf("Let's do it again!");
goto point1;
}
}
printf("Now please enter the date :\n");
printf("Y,M,D");
putchar ('\n');
scanf("%d,%d,%d",&y1,&m1,&d1);//get the date
if (m1>=13||m1<0)
{printf("error!\nPlease enter right date!");
goto point2;
}
/*time to calculate*/
y0=y1-y0;
if ((d1-d0<=0)||(m1-m0<=0))
y0--;
printf("Well your age must be %d ",y0);
m0=m1-m0;
m0*=-1;
d0=d1-d0;
if (d1-d0<=0)
m0--;
d0*=-1;
printf("And you have left %d years,%d mounth,%d days!",y0,m0,d0);
putchar('\n');
/*time to judje*/
printf("Is it right?\n");
scanf("%s",&answer);
if (answer=='y'||answer=='Y')
printf("(ノOVO)ノ");//(ノOVO)ノ
else {printf(":p\n");
printf("Let's do it again!");
goto point1;
}
}
我发现,C语言没办法打颜文字欸……