这个程序哪里错了??
rt,求解,出了点小毛病。。。#include<stdio.h>#include"zylib.h"int year(int x);BOOL isyear(int x);int sumyear(int x,int t);int days(int y,int a );typedef enum{SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY}WEEKDAY;int main(){int x,y,t,sum,a,sumdays,date,dates;const WEEKDAY original_date=MONDAY;WEEKDAY weekday;printf("a number:\n");x=GetRealFromKeyboard();printf("a number:\n");y=GetRealFromKeyboard();t=year(x);printf("%d\n",t);sum=sumyear(x,t);printf("%d\n",sum);a=isyear(x);printf("%d\n",a);sumdays=sum+days(y,a);printf("%d\n",sumdays);dates=days(y+1,a)-days(y,a);printf("Calendar %d-%d\n",x,y);printf("--------------------------\n");printf("SuMoTuWeThFrSa\n");printf("--------------------------\n");for( date=1;date<=dates;++date){weekday=(WEEKDAY)((date+(int)original_date-1+sumdays)%7);switch(weekday){case SUNDAY: printf("%2d",date);break;case MONDAY: printf("%4d",date);break;case TUESDAY: printf("%4d",date);break;case WEDNESDAY: printf("%4d",date);break;case THURSDAY: printf("%4d",date);break;case FRIDAY: printf("%4d",date);break;case SATURDAY: printf("%4d\n",date);break;default:;}}printf("--------------------------\n");return 0;} int year(int x){int t;t=0;while(x-1>2007){t += isyear(x-1); x--;}return t;}BOOL isyear(int x){return x%4==0&&x%100!=0||x%400==0;}int sumyear(int x,int t){int sum;sum=365*(x-2007-t)+366*t;return sum;}int days(int y,int a){int b;while(y>=1&&y<=12){if(y==1) return b=0;else if(y==2) return b=31;else if(y==3) return b=59+a;else if(y==4) return b=90+a;else if(y==5) return b=120+a;else if(y==6) return b=151+a;else if(y==7) return b=181+a;else if(y==8) return b=212+a;else if(y==9) return b=243+a;else if(y==10) return b=273+a;else if(y==11) return b=304+a;else if(y==12) return b=334+a;}printf("error\n");return b=-1;}这是一个日历 没回车……,看起来难受…… 如果是C语言的话,貌似没有bool吧?
#include<stdio.h>
#include"zylib.h"
int year(int x);
BOOL isyear(int x);
int sumyear(int x,int t);
int days(int y,int a );
typedef enum{
SUNDAY,MONDAY,TUESDAY,WEDNESDAY,THURSDAY,FRIDAY,SATURDAY}
WEEKDAY;
int main()
{
int x,y,t,sum,a,sumdays,date,dates;
const WEEKDAY original_date=MONDAY;WEEKDAY weekday;
printf("a number:\n");
x=GetRealFromKeyboard();
printf("a number:\n");
y=GetRealFromKeyboard();
t=year(x);
printf("%d\n",t);
sum=sumyear(x,t);
printf("%d\n",sum);
a=isyear(x);
printf("%d\n",a);
sumdays=sum+days(y,a);
printf("%d\n",sumdays);
dates=days(y+1,a)-days(y,a);
printf("Calendar %d-%d\n",x,y);
printf("--------------------------\n");
printf("SuMoTuWeThFrSa\n");
printf("--------------------------\n");
for( date=1;date<=dates;++date)
{
weekday=(WEEKDAY)((date+(int)original_date-1+sumdays)%7);
switch(weekday)
{
case SUNDAY:
printf("%2d",date);break;
case MONDAY:
printf("%4d",date);break;
case TUESDAY:
printf("%4d",date);break;
case WEDNESDAY:
printf("%4d",date);break;
case THURSDAY:
printf("%4d",date);break;
case FRIDAY:
printf("%4d",date);break;
case SATURDAY:
printf("%4d\n",date);break;
default:;
}
}
printf("--------------------------\n");
return 0;
}
int year(int x)
{
int t;
t=0;
while(x-1>2007)
{
t += isyear(x-1);
x--;
}
return t;
}
BOOL isyear(int x)
{
return x%4==0&x%100!=0||x%400==0;
}
int sumyear(int x,int t)
{
int sum;sum=365*(x-2007-t)+366*t;
return sum;
}
int days(int y,int a)
{
int b;
while(y>=1&&y<=12)
{
if(y==1) return b=0;
else if(y==2) return b=31;
else if(y==3) return b=59+a;
else if(y==4) return b=90+a;
else if(y==5) return b=120+a;
else if(y==6) return b=151+a;
else if(y==7) return b=181+a;
else if(y==8) return b=212+a;
else if(y==9) return b=243+a;
else if(y==10) return b=273+a;
else if(y==11) return b=304+a;
else if(y==12) return b=334+a;
}
printf("error\n");
return b=-1;
}
奇怪,明明打了回车的。
谢谢了。 不如存成cpp,这样就可以用bool了
页:
[1]