2
votes

i cannot get this code to compile in gcc. ive tried changing the call_celsius to calculate as well as changing it from uppercase to lowercase. im not sure if its because i didnt declare a variable which i dont think is the case, or if i did the call function wrong.

/* 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);
}

these are the errors i receive

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

1 Answers

1
votes

You didn't declare call_celsius and call_fahrenheitbefore you used them. Either add function prototypes or declare & define the functions. Here are examples of forward declarations:

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