主文件
#include"pch.h"
#include<stdio.h>
#include"4-15-2.cpp"
#define PI 3.14
double c;
double s;
int main(void)
{
double r;
printf("please input the r of the circle\n");
scanf_s("%lf", &r);
fuc(r);
printf("c=%lf", c);
printf("s=%lf", s);
getchar();
return 0;
}
文件4-15-2
#include"pch.h"
#define PI 3.14
extern double c, s;
void fuc(double r)
{
c = 2 * PI*r;
s = PI * r*r;
}
这是一个计算圆的周长和面积的程序,我在vs2017上运行显示这样的错误
这是我的源文件列表
刚入坑小白希望大神帮忙解答一下,感谢!
把主文件中得#include"4-15-2.cpp"删除即可
4-15-2.cpp这么编写
再编写一个4-15-2.h,内容是
extern void fuc(double r);
然后主程序include "4-15-2.h"
第一种方法:把主文件里的#include"4-15-2.cpp"删了,并在"pch.h"头文件中加"void fuc(double r);"就ok了,头一次遇到使用#include "xxxx.cpp",是我孤陋寡闻了么?一般都是xxxx.h的。
第二种方法:把主文件里的#include"4-15-2.cpp"删了,并在主函数中添加extern void fuc(double r);//声明fuc函数是在外部定义