为什么我的两个计算功能都出现了未解决的外部系统错误(错误LNK2019)? 错误6错误LNK2019:未解析的外部符号_CalculateAreaRec 错误7错误LNK2019:未解析的外部符号_CalcCircleArea被引用 错误8错误LNK1120:2个未解析的外部
#include <math.h>
#include <stdio.h>
#define PI 3.14159
#define _CRT_SECURE_NO_WARNINGS //to avoid scanf warning or error
/* Function prototype */
int CalculateAreaRec(int length, int width);
double CalcCircleArea(double radius);
int GetInt(void);
int main(void)
{
//Declared varibles
double radius;
int length;
int width;
int GetInt(void);
{
// this function gets an integer from the user and returns it
// this function is called 3 times from main
//Prompt for the radius of the circle.
printf("Whats the radius of the circle \n");
//Get the radius from the keyboard.
scanf("%lf", &radius);
//Display the radius and area of the circle onto the screen.
printf(" The radius is %lf and the area is %.4f \n", radius, CalcCircleArea(radius));
//Prompt for the length of a side
printf("Whats the length of a side of rectangle \n");
//Get the length from the keyboard
scanf("%d", &length, CalculateAreaRec(length, width));
//Prompt for the width of a side
printf("Whats length of the width \n");
//Get the width from the keyboard
scanf(" %d", &width, CalculateAreaRec(length, width));
//Display the side length, width, and area of the rectangle onto the screen.
printf(" The side length is %d the width is %d and the area of the rectangle is %d \n ", length, width, CalculateAreaRec);
}
double CalcCircleArea(double radius);
{
//Calculate the area of the circle (use 3.14).
return (PI * radius * radius);
}
int CalculateAreaRec(int length, int width);
//takes two arguments (base and height of the triangle) and returns the area
{
return (length*width);
//takes one argument (radius of the circle) and returns the area
}
}
答案 0 :(得分:1)
C不支持嵌套函数。他们都必须生活在最高层,彼此独立。
除此之外,您的main
似乎没有任何代码可以调用其他功能。
您还错误地致电CalculateAreaRec
。它不应该是scanf
的参数,您需要将它作为printf
的参数调用。
答案 1 :(得分:0)
因为您定义了一些函数,然后尝试以错误的方式在main
方法中声明它们,所以您拥有的是
double CalcCircleArea(double radius);
int main() {
...
double CalcCircleArea(double radius); // <- this semicolon saves you from a compilation error
// because this line is interpreted as a forward declaration and block below as a scope
{
..
}
}
但你应该
double CalcCircleArea(double radius);
int main()
{
..
}
double CalcCircleArea(double radius) // <- no semicolon
{
..
}