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

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 fulln");
x05printf("year.The year must not be before 1900.n");
}
int getyearfromuser(void)
{
int year;
x05while(1)
x05{
x05 printf("Which year?n");
x05x05scanf("%ld",&year);
x05x05getchar();
x05
x05x05if(year>=1900)
x05x05x05return(year);
x05x05printf("The year must be at least 1900.n");
x05}
}
int getmonthfromuser(void)
{
int month;
x05while(1)
x05{
x05 printf("Which month?");
x05x05scanf("%d",&month);
x05x05getchar();
x05x05return month;
x05}
}
int monthdays(int month,int year)
{
x05switch(month)
x05{
x05case 2:if(isleapyear(year))
x05x05x05x05return (29);
x05x05 else
x05x05x05x05 return (28);
case 4:
x05case 6:
x05case 9:
x05case 11:
x05x05return(30);
x05default :
x05x05return(31);
x05}
}
int firstdayofmonth(int month,int year)
{
int weekday,i;
x05weekday=tuesday;
x05for(i=1900;i
大家的vv 1年前 已收到1个回答 举报

a24534b31b0b3082 幼苗

共回答了15个问题采纳率:86.7% 举报

#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 fulln");
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

1年前 追问

4

大家的vv 举报

您做了修改了吗!! 还是老样子啊

举报 a24534b31b0b3082

首先睁大眼睛,其次你把我改过的运行下不就知道了,亲测正常,还有你的编程习惯不好,有很多小错误
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 17 q. 0.020 s. - webmaster@yulucn.com