我无法让这段代码在 gcc 中编译。我试过更改 call_celsius 来计算以及将其从大写更改为小写。我不确定是不是因为我没有声明一个我认为不是这种情况的变量,或者我是否错误地调用了函数。
/* Homework 1 Question 2 */
/* Purpose: Takes a depth (in kilometers) inside the earth */
/* as input data; Computes and displays the temperature at */
/* depth in degrees Celsius and degrees Fahrenheit. */
#include <stdio.h>
int main(void)
{
/* Declare Variables */
double depth;
double Celsius;
double Fahrenheit;
/* Obtain Data */
printf("Please enter depth(in kilometers) inside the Earth: ");
scanf("%lf",&depth);
/* Calculate */
Celsius = call_celsius(depth);
Fahrenheit = call_fahrenheit(Fahrenheit);
/* Output */
printf("The temperature at %lf kilometers is %lf degrees Celsius and %lf degrees Fahrenheit",depth, Celsius, Fahrenheit);
return 0;
}
double call_celsius(double depth)
{
return((10 * depth) + 20);
}
double call_fahrenheit(double Celsius)
{
return((1.8 * Celsius) + 32);
}
这些是我收到的错误
homework1question2.c:35:8: error: conflicting types for ‘call_celsius’
double call_celsius(double depth)
^
homework1question2.c:25:11: note: previous implicit declaration of ‘call_celsius’ was here
Celsius = call_celsius(depth);
^
homework1question2.c:40:8: error: conflicting types for ‘call_fahrenheit’
double call_fahrenheit(double Celsius)
^
homework1question2.c:26:14: note: previous implicit declaration of ‘call_fahrenheit’ was here
Fahrenheit = call_fahrenheit(Fahrenheit);
最佳答案
在使用它们之前,您没有声明 call_celsius
和 call_fahrenheit
。添加函数原型(prototype)或声明和定义函数。以下是前向声明的示例:
double call_celsius(double depth);
double call_fahrenheit(double Celsius);
int main(void) {
关于c++ - 获取错误 : "error: conflicting types for ‘call_celsius’ "and "note: previous implicit declaration of ‘call_celsius’ was here",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21641244/