作业帮 > 综合 > 作业

VC++打印日历中某月第一天是星期几的问题 已知1900年1月1日为星期一

来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/19 06:08:03
VC++打印日历中某月第一天是星期几的问题 已知1900年1月1日为星期一
出现的问题是 不管输入什么,结果总是weekday=monday 的前一天,即星期日
如果输入,weekday=tuesday,得出 星期一
小弟苦苦思索,仍然无果,希望哪位大侠出手相助啊!
代码如下:
#include
#include
#define sunday 0
#define monday 1
#define tuesday 2
#define wednesday 3
#define thurday 4
#define friday 5
#define saturday 6
void giveinstructions(void);
int getyearfromuser(void);
int getmonthfromuser(void);
int monthdays(int month,int year);
int firstdayofmonth(int month,int year);
bool isleapyear(int year);
void main(void)
{
int year,month,weekday;
\x05 giveinstructions();
\x05 year=getyearfromuser();
\x05 month=getmonthfromuser();
weekday=firstdayofmonth(year,month);
\x05 printf("%d",weekday);
getchar();
}
void giveinstructions(void)
{
printf("This program displays a calendar for a full\n");
\x05printf("year.The year must not be before 1900.\n");
}
int getyearfromuser(void)
{
int year;
\x05while(1)
\x05{
\x05 printf("Which year?\n");
\x05\x05scanf("%ld",&year);
\x05\x05getchar();
\x05
\x05\x05if(year>=1900)
\x05\x05\x05return(year);
\x05\x05printf("The year must be at least 1900.\n");
\x05}
}
int getmonthfromuser(void)
{
int month;
\x05while(1)
\x05{
\x05 printf("Which month?");
\x05\x05scanf("%d",&month);
\x05\x05getchar();
\x05\x05return month;
\x05}
}
int monthdays(int month,int year)
{
\x05switch(month)
\x05{
\x05case 2:if(isleapyear(year))
\x05\x05\x05\x05return (29);
\x05\x05 else
\x05\x05\x05\x05 return (28);
case 4:
\x05case 6:
\x05case 9:
\x05case 11:
\x05\x05return(30);
\x05default :
\x05\x05return(31);
\x05}
}
int firstdayofmonth(int month,int year)
{
int weekday,i;
\x05weekday=tuesday;
\x05for(i=1900;i
VC++打印日历中某月第一天是星期几的问题 已知1900年1月1日为星期一
#include
#include
#define sunday 0
#define monday 1
#define tuesday 2
#define wednesday 3
#define thurday 4
#define friday 5
#define saturday 6
void giveinstructions(void);
int getyearfromuser(void);
int getmonthfromuser(void);
int monthdays(int month, int year);
int firstdayofmonth(int month, int year);
bool isleapyear(int year);
void main(void)
{
int year,month,weekday;
giveinstructions();
year=getyearfromuser();
month=getmonthfromuser();
weekday=firstdayofmonth(month,year);
printf("%d",weekday);
getchar();
}
void giveinstructions(void)
{
printf("This program displays a calendar for a full\n");
printf("year. The year must not be before 1900.\n");
}
int getyearfromuser(void)
{
int year;
while(1)
{
printf("Which year?\n");
scanf("%ld",&year);
getchar();
if(year>=1900)
return(year);
printf("The year must be at least 1900.\n");
}
}
int getmonthfromuser(void)
{
int month;
while(1)
{
printf("Which month?\n");
scanf("%d",&month);
getchar();
return month;
}
}
int monthdays(int month,int year)
{
switch(month)
{
case 1:
return 0;
case 2: if(isleapyear(year))
return (29);
else
return (28);
case 4:
case 6:
case 9:
case 11:
return(30);
default :
return(31);
}
}
int firstdayofmonth(int month, int year)
{
int weekday,i;
weekday=monday;
for(i=1900;i
再问: 您做了修改了吗!! 还是老样子啊
再答: 首先睁大眼睛,其次你把我改过的运行下不就知道了,亲测正常,还有你的编程习惯不好,有很多小错误