Thread: Need help on a fairly simple code

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    1

    Need help on a fairly simple code

    So the problem is that I have to get input from the user for the depth and then make that into Celsius and Fahrenheit using the formulas DC=10*Depth+20 and DF=1.8*DC+32 respectively. Here's what I've got so far, and it is picking up the Depth from the user, but I don't know how to make that depth carry to the functions below. It's not erroring and it keeps displaying 1.00 for the Depth (if I put 1), but 0.00 for both Celsius and Fahrenheit.

    Thanks for the help in advance

    Code:

    Code:
    #include<stdio.h>
    
    /*Function Prototypes*/
    void convert_celsius(void); /*determines the degrees in Celsius*/
    void convert_fahrenheit(void); /*Converts Celsius to Fahrenheit*/
    
    /*Name: main*/
    int
    main(DegreesCelsius, DegreesFahrenheit)
    {
    
    double DepthInKm; /*depth inside earth in kilometers*/
    /*get the depth in kilometers*/
    printf("EE 233 Fall 2012,P2: Depth to Celsius and Fahrenheit Conversion Program.\n\nEnter a depth in kilometers: "); scanf("%lf", &DepthInKm); /*compute the degrees in Celsius*/ convert_celsius(DepthInKm); /*compute the degrees in Fahrenheit*/ convert_fahrenheit(DegreesCelsius); /*display the result in a paragraph*/ printf("EE 233 Fall 2012,P2, dhc10, Daniel H. Camburn\n\nFor a depth of %.2f kilometers, the ", DepthInKm); printf("temperature is %.2f degrees Celsius, and %.2f degrees Fahrenheit.\n", DegreesCelsius, DegreesFahrenheit); return(0);
    } /* *Determines degrees in Celsius at the given depth */ void convert_celsius(DepthInKm) {
    double degrees_celsius; /*temperature in Celsius of the depth*/ degrees_celsius=(10*DepthInKm)+20;
    } /* *Converts Celsius to degrees Fahrenheit */ void convert_fahrenheit(DegreesCelsius) {
    double degrees_fahrenheit; /*temperature in Fahrenheit of the depth*/ degrees_fahrenheit=(1.8*DegreesCelsius)+32;
    }

    Last edited by Daniel Camburn; 09-07-2012 at 01:46 PM.

  2. #2
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    What language is that supposed to be?

    If that is supposed to be C, then no it isn't "Depth" because it isn't compiling.

    Look, just do yourself a favor and ignore this task for now; get and thoroughly study a good book ("The C Programming Language").

    Soma

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    The argument lists in your function declarations; i.e.

    Code:
    void convert_celsius(void); /*determines the degrees in Celsius*/
    ... do not match the argument lists in your function definitions; i.e.

    Code:
    void convert_celsius(DepthInKm)
    Furthermore, when you calculate the temperature in Celsius, then in Fahrenheit, you're not storing the results anywhere (the variables "DegreesCelsius" and "DegreesFahrenheit" remain unchanged).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Fairly new to C, got a few problems.
    By Woobly in forum C Programming
    Replies: 11
    Last Post: 08-11-2011, 03:12 PM
  2. Need help in a fairly simple C prog
    By CodeSlow in forum C Programming
    Replies: 4
    Last Post: 01-04-2008, 02:49 AM
  3. Fairly simple problem
    By fatdunky in forum C Programming
    Replies: 1
    Last Post: 11-14-2005, 11:34 PM
  4. Fairly simple classes help please
    By sammacs in forum C++ Programming
    Replies: 13
    Last Post: 12-01-2004, 10:42 AM
  5. This should be fairly simple to fix.
    By Lancer in forum C++ Programming
    Replies: 3
    Last Post: 03-04-2004, 08:57 PM