error C2365: 'leap' : redefinition; previous definition was 'data variable'
和
error C2365: 'count' : redefinition; previous definition was 'data variable'
源代码:
#include <stdio.h>
int main(void){
int d, m, y, x, day, leap, count;
//Input values for date
printf("\n Input the Day: ");
scanf_s("%f", &d);
printf("\n Input the Month: ");
scanf_s("%f", &m);
printf("\n Input the Year: ");
scanf_s("%f", &y);
//End input
int count(int m, int day);
int leap(int y, int x);
if (x == 1){
printf("\nThe day of the year is %f", day + 1);
}
else{
printf("\nThe day of the year is %f", day);
}
system("pause");
return(0);
}
//Count the number of days
int count(int m, int day, int d){
if (m == 1){
day = d;
}
if (m == 2){
day = 31 + d;
}
if (m == 3){
day = 59 + d;
}
if (m == 4){
day = 90 + d;
}
if (m == 5){
day = 120 + d;
}
if (m == 6){
day = 151 + d;
}
if (m == 7){
day = 181 + d;
}
if (m == 8){
day = 212 + d;
}
if (m == 9){
day = 243 + d;
}
if (m == 10){
day = 273 + d;
}
if (m == 11){
day = 304 + d;
}
if (m == 12){
day = 334 + d;
}
return(day);
}
//Determine if it's a leap year
int leap(int y, int x){
if (y % 400 == 0){
x = 1;
}
else if (y % 100 == 0){
x = 0;
}
else if (y % 4 == 0){
x = 1;
}
else{
x = 0;
}
return(x);
}
答案 0 :(得分:0)
无需声明函数leap
和count
类似数据类型。
int d, m, y, x, day, leap, count;
删除leap
和count
,如下所示
int d, m, y, x, day;
下面是你的函数原型,这是正确的(足够编译器)
int count(int m, int day);
int leap(int y, int x);
答案 1 :(得分:0)
count
和leap
在main
中的变量和函数名称相同,无效。
答案 2 :(得分:0)
以下是函数声明,main()
中不允许这些函数声明(本地函数定义是非法的)。你应该把它们放在main()
之前。
int count(int m, int day);
int leap(int y, int x);
此外,根据您的定义,count()
的函数声明应为:
int count(int m, int day, int d);
并删除int leap, count;
,这是数据类型的声明(此处为int
),而不是函数。
如果您想在main()
中调用它们,请使用:
count(m, day, d);
leap(y, x);