2014-02-08 37 views
2

我無法獲得此代碼在gcc中編譯。我嘗試改變call_celsius來計算以及將它從大寫改爲小寫。即時通訊不知道,因爲我沒有聲明一個變量,我不認爲是這種情況,或者如果我做了錯誤的調用函數。獲取錯誤:「錯誤:'call_celsius'和'note:'之前的隱式聲明'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); 

回答

1

你沒有申報call_celsiuscall_fahrenheit你使用它們之前。既可以添加函數原型,也可以聲明定義函數。以下是正向聲明的示例:

double call_celsius(double depth); 
double call_fahrenheit(double Celsius); 
int main(void) { 
+0

woot woot!謝謝!不知道你需要聲明這些變量......實際上並不知道它們是他們自己的變量。感謝您的幫助。編譯和運行順利。 :) – hugo1391

+0

@ user3286135如果我解決了這個問題,您可以將答案標記爲接受:) – yizzlez

+0

完成。再次感謝你 – hugo1391

1

請提及錯誤函數的原型。