C while循环中的“未声明:函数首次使用错误”,尽管声明
在unix计算机上使用gcc编译时,以下代码引发以下错误:C while循环中的“未声明:函数首次使用错误”,尽管声明,c,gcc,C,Gcc,在unix计算机上使用gcc编译时,以下代码引发以下错误: eu.c: In function 'main': eu.c:23: error: 'valuetoAdd' undeclared (first use in this function) eu.c:23: error: (Each undeclared identifier is reported only once eu.c:23: error: for each function it appears in.) 代码如下:我已经
eu.c: In function 'main':
eu.c:23: error: 'valuetoAdd' undeclared (first use in this function)
eu.c:23: error: (Each undeclared identifier is reported only once
eu.c:23: error: for each function it appears in.)
代码如下:我已经声明了要添加的变量值。为什么不起作用
#include <stdio.h>
int main (void)
{
float input;
float e = 0;
int count = 0;
int flag = 1;
float valueToAdd = 0.0;
do
{
printf("Enter input: ");
scanf("%f", &input);
} while (input < 0);
while (flag)
{
valueToAdd = 1 / factorial(count);
e += valuetoAdd;
count++;
flag = input < valueToAdd;
}
printf("The computed value of e is: %.15f", e);
printf("%d terms were required", count++);
}
int factorial (int c)
{
if (c == 0) return 1;
else return c * factorial(c-1);
}
实际上,您没有声明要添加的值。您声明了valueToAdd,但这是另一个标识符。标识符在C中区分大小写。它应该是valueToAdd,您正在使用valueToAdd。。检查箱子 您需要在main之上创建一个原型,或者需要在main之上声明它。另外,main应该返回一个int。我做了,它仍然抛出相同的错误。哈哈,令人尴尬的错误。谢谢
valueToAdd = 1 / factorial(count);
e += valuetoAdd; <= Problem is here, valuetoAdd undeclared !