Thread: please compile my C program and help with my errors

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    3

    please compile my C program and help with my errors

    I have to write a program to take a depth (in kilometers) inside the earth as input data; compute and display the temperature at this depth in degrees Celsius and degrees Fahrenheit. So basically, when I compile my program, it should allow me to enter the depth value first. The relevant formulas are:

    Celsius = 10 * depth + 20

    Fahrenheit = 9/5 * Celcius + 32

    I have to include three functions in my program.

    Function celciusAtDepth should compute and return the Celsius temperature at a depth measured in kilometers.


    Function celsiusToFahrenheit should convert a Celcius temperature to Fahrenheit.

    Function printResults should take in the two temperatures and print them.

    Note: all the function inputs should be done in main and the all the outputs shoud be done in printResults.

    I also don't want my results to be (celsius, fahrenheit) on the same line. I want celsius answer in one line and fahrenheit answer in another line. thank you.
    Code:
    #include <stdio.h>
     
      /* Function Declaration */
      double celsiusAtDepth;
      double celsiusToFahrenheit;
      void printResults;
      
      int main()
    {
        double depth;
        printf("Enter a depth value: ");
        scanf("&#37;lf", &depth);
        
        double celsius=celsuisAtDepth;
        double fahrenheit=celsiusToFahrenheit(celsius);
        PrintResults(celsius, fahrenheit);
        
        return (0);
    }
     /* Celsius=10*depth=20 */
     double celsiusAtDepth (double depth)
    {
        return(10*depth+20);
    }
     /*Fahrenheit=((9.0/5.0)*celsius+32) */
     double celsiusToFahrenheit (double celsius)
    {
       return((9.0/5.0)*celsius+32);
    }
     /*Function printResults should take in the two temperatures and print them. */
    void printResults (double celsius, double fahrenheit)
    {
       printf("Celsius: %lf\nFahrenheit: %lf\n", celsius, fahrenheit); 
    }
    I run the compiler gcc, so it looks like this: gcc -Wall -ansi -pedantic -file name
    I got of lot of errors.
    Last edited by Salem; 04-22-2008 at 10:03 AM. Reason: cut the font / size / colour abuse

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    214
    1. This is the C# forum.

    2. You aren't passing your depth value to celsiusAtDepth()

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    The error message(s) will tell you what and (more conveniently) where the errors are located, so you can track them down easily.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Code:
    /* Function Declaration */
      double celsiusAtDepth;
      double celsiusToFahrenheit;
      void printResults;
    No, it is not...
    Code:
    double celsiusAtDepth (double depth); /* this IS function declaration */
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Function declarations are incorrect.
    Incorrect calling of functions.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed