2016-02-13 1 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

С не поддерживает вложенные функции. Все они должны жить на самом высоком уровне, независимо друг от друга.

Кроме того, у вашего 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

Теперь im получаю ошибку C2143: синтаксическая ошибка: отсутствует ';' before '{' \t для обеих функций –

+0

@EsMosca Вы не разложили функции или просто удалили ';'? – dbush

+0

Я думаю, что я не разблокировал функции, но я не могу найти никакой информации об этом –

Смежные вопросы