C++程序:给出年月日,计算该日是该年的第几天
无论怎么调试,还是有4个错误,望各位大侠帮忙改一下,谢了!#include<iostream>usingnamespacestd;main()//用sum_day和lea...
无论怎么调试,还是有4个错误,望各位大侠帮忙改一下,谢了!
#include<iostream>
using namespace std;
main()//用sum_day和leap函数计算天数
{
int year, month, day;
int days;
cout<<"请输入日期(年,月,日)"<<endl;
cin>>year>>month>>day;
days=sum_day(month,day);
if (leap(year)&&month>=3)
days=days+1;
cout<<"是该年的第"<<days<<"天"<<endl;
return 0;
}
static int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}
int sum_day(month,day)//计算日期
int month,day;
{
int i;
for (i=1;i<month;i++)//累加所在月之天数
day+=day_tab[i];
return day;
}
int leap(year)//判断闰年
int year;
{
int leap;
leap=(year%4==0 && year%100=0 || year%400==0);
return(leap);
}
错误提示:Compiling...
计算日期.cpp
F:\C++程序\计算日期.cpp(11) : error C2065: 'sum_day' : undeclared identifier
F:\C++程序\计算日期.cpp(12) : error C2065: 'leap' : undeclared identifier
F:\C++程序\计算日期.cpp(20) : error C2144: syntax error : missing ';' before type 'int'
F:\C++程序\计算日期.cpp(20) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
计算日期.obj - 4 error(s), 0 warning(s) 展开
#include<iostream>
using namespace std;
main()//用sum_day和leap函数计算天数
{
int year, month, day;
int days;
cout<<"请输入日期(年,月,日)"<<endl;
cin>>year>>month>>day;
days=sum_day(month,day);
if (leap(year)&&month>=3)
days=days+1;
cout<<"是该年的第"<<days<<"天"<<endl;
return 0;
}
static int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}
int sum_day(month,day)//计算日期
int month,day;
{
int i;
for (i=1;i<month;i++)//累加所在月之天数
day+=day_tab[i];
return day;
}
int leap(year)//判断闰年
int year;
{
int leap;
leap=(year%4==0 && year%100=0 || year%400==0);
return(leap);
}
错误提示:Compiling...
计算日期.cpp
F:\C++程序\计算日期.cpp(11) : error C2065: 'sum_day' : undeclared identifier
F:\C++程序\计算日期.cpp(12) : error C2065: 'leap' : undeclared identifier
F:\C++程序\计算日期.cpp(20) : error C2144: syntax error : missing ';' before type 'int'
F:\C++程序\计算日期.cpp(20) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
计算日期.obj - 4 error(s), 0 warning(s) 展开
展开全部
# include <stdio.h>
# include <conio.h>
int sum_day(int month, int day);
int leap(int year);
void main()
{
int year, month, day;
int days;
printf("请输入日期(年,月,日):");
scanf("%d, %d, %d", &year, &month, &day);
printf("%d年%d月%d日", year, month, day);
days = sum_day(month, day);
if(leap(year) && month>=3)
days = days + 1;
printf("是该年的第%d天.\n", days);
getch();
}
static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_day(int month, int day)
{
int i;
for(i=1; i<month; i++)
day = day + day_tab[i];
return day;
}
int leap(int year)
{
int leap;
leap = (year%4==0&&year%100!=0)||(year%400==0);
return leap;
}
没调试过,机子上暂时没工具,应该是没问题了。你试试
# include <conio.h>
int sum_day(int month, int day);
int leap(int year);
void main()
{
int year, month, day;
int days;
printf("请输入日期(年,月,日):");
scanf("%d, %d, %d", &year, &month, &day);
printf("%d年%d月%d日", year, month, day);
days = sum_day(month, day);
if(leap(year) && month>=3)
days = days + 1;
printf("是该年的第%d天.\n", days);
getch();
}
static int day_tab[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int sum_day(int month, int day)
{
int i;
for(i=1; i<month; i++)
day = day + day_tab[i];
return day;
}
int leap(int year)
{
int leap;
leap = (year%4==0&&year%100!=0)||(year%400==0);
return leap;
}
没调试过,机子上暂时没工具,应该是没问题了。你试试
展开全部
#
include
<stdio.h>
#
include
<conio.h>
int
sum_day(int
month,
int
day);
int
leap(int
year);
void
main()
{
int
year,
month,
day;
int
days;
printf("请输入日期(年,月,日):");
scanf("%d,
%d,
%d",
&year,
&month,
&day);
printf("%d年%d月%d日",
year,
month,
day);
days
=
sum_day(month,
day);
if(leap(year)
&&
month>=3)
days
=
days
+
1;
printf("是该年的第%d天.\n",
days);
getch();
}
static
int
day_tab[13]
=
{0,
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31};
int
sum_day(int
month,
int
day)
{
int
i;
for(i=1;
i<month;
i++)
day
=
day
+
day_tab[i];
return
day;
}
int
leap(int
year)
{
int
leap;
leap
=
(year%4==0&&year%100!=0)||(year%400==0);
return
leap;
}
没调试过,机子上暂时没工具,应该是没问题了。你试试
include
<stdio.h>
#
include
<conio.h>
int
sum_day(int
month,
int
day);
int
leap(int
year);
void
main()
{
int
year,
month,
day;
int
days;
printf("请输入日期(年,月,日):");
scanf("%d,
%d,
%d",
&year,
&month,
&day);
printf("%d年%d月%d日",
year,
month,
day);
days
=
sum_day(month,
day);
if(leap(year)
&&
month>=3)
days
=
days
+
1;
printf("是该年的第%d天.\n",
days);
getch();
}
static
int
day_tab[13]
=
{0,
31,
28,
31,
30,
31,
30,
31,
31,
30,
31,
30,
31};
int
sum_day(int
month,
int
day)
{
int
i;
for(i=1;
i<month;
i++)
day
=
day
+
day_tab[i];
return
day;
}
int
leap(int
year)
{
int
leap;
leap
=
(year%4==0&&year%100!=0)||(year%400==0);
return
leap;
}
没调试过,机子上暂时没工具,应该是没问题了。你试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询