2016-02-13 24 views
-1

爲什麼我會收到一個未解決的外部系統錯誤(錯誤LNK2019)爲我的兩個計算功能? 錯誤6錯誤LNK2019:解析外部符號_CalculateAreaRec 錯誤7錯誤LNK2019:解析外部符號_CalcCircleArea引用 錯誤8錯誤LNK1120:2周解析的外部爲什麼我會收到一個未解決的外部系統錯誤(錯誤LNK2019)爲我的兩個計算功能?

#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 
    } 
} 
+2

你的代碼中有這麼多錯誤。請閱讀一本好書/教程。 –

回答

1

C不支持嵌套函數。他們都必須生活在最高層次,彼此獨立。

除此之外,您main不會出現任何代碼在它調用等功能。

你還呼籲CalculateAreaRec不正確。它不應該是scanf的參數,並且您需要將它作爲參數調用到printf的參數中。

+0

我怎麼能叫一個函數 –

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 
{ 
    .. 
} 
+0

現在我得到錯誤C2143:語法錯誤:缺少';'之前'{'\t對於這兩個函數 –

+0

@EsMosca你是否嵌套函數,或者刪除';'? – dbush

+0

我想我沒有取消功能,但我找不到任何信息 –

相關問題