下面是我编写的求出今天是今年的第几天的程序,运行一切正常。可是为什么我输入一个字母的时候就会造成死循环呢?想不通~~~~哪位朋友讲解一下,谢谢
#include<stdio.h>
struct date
{
int year;
int month;
int day;
}today;
int main()
{
int i,month_days,total_days=0;
loop:printf("请输入今天的日期:");
scanf("%d%d%d",&today.year,&today.month,&today.day);
if(today.year<0||today.month>12||today.month<=0||today.day<=0||today.day>31) goto loop;
printf("今天是 %d-%d-%d\n",today.year,today.month,today.day);
for(i=1;i<today.month;i++)
{
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12) month_days=31;
else
if(i==4||i==6||i==9||i==11) month_days=30;
else
if(today.year%400==0||today.year%4==0&&today.year%100!=0) month_days=29;
else month_days=28;
total_days+=month_days;
}
total_days+=today.day;
printf("今天是%d的第%d天!\n",today.year,total_days);
getch();
}
[此贴子已经被作者于2007-6-9 3:25:11编辑过]