未定义的对“Function”C的引用

时间:2016-02-26 21:04:27

标签: c compiler-errors

我已经研究过这个错误的解决方案,但我仍然没有得到它。

> Run Save Update Fork Tidy Collaborate Sign in

我正在使用ideone.com并仍然收到相同的错误消息(#include <stdio.h> float calcF(float a, float b, float c); int main(void) { float mag_flux_den, cur, len; float result; printf("What is the magnetic flux density in tesla? : "); scanf("%f", &mag_flux_den); printf("What is the current in the conductor in Amperes? : "); scanf("%f", &cur); printf("What is the length of the conductor in the magnetic field in metres? : "); scanf("%f", &len); result = calcF(mag_flux_den, cur, len); printf("Force on the current carrying conductor: %f", result); return 0; } float calcf(float a, float b, float c) //calculates force on the current carrying conductor{ float F; F = a * b * c; return F; } )。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:2)

您将函数声明为“calcF”,大写字母为“F”,但您的定义为“calcf”,小写为“f”。确保它们是相同的。

此外,您的代码块底部的函数定义在注释的末尾有一个开括号。

在评论后移动它。

答案 1 :(得分:1)

试试这个:

#include <stdio.h>
#include <cs50.h> 

float calcF(float a, float b, float c); 

int main(void) 
{
      float mag_flux_den, cur, len; 
      float result;

      printf("What is the magnetic flux density in tesla? : ");
      scanf("%f", &mag_flux_den);
      printf("What is the current in the conductor in Amperes? : ");
      scanf("%f", &cur);
      printf("What is the length of the conductor in the magnetic field in metres? : ");
      scanf("%f", &len);

      result = calcF(mag_flux_den, cur, len);

      printf("Force on the current carrying conductor: %f", result);
      return 0;
}

float calcF(float a, float b, float c) //calculates force on the current carrying conductor
{
      float F;
      F = a * b * c;
      return F;   
}