1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C program using functions to convert Fahrenheit and Celsius

  1. Oct 20, 2015 #1
    1. The problem statement, all variables and given/known data
    Hi i have an assignment that is asking me to convert 3 temperatures in fahrenheit to celcius and vice versa.
    I am very new to programming only 2 weeks in(and i learn by playing with the program) so I do not know all of the terminology / principles.

    I am not allowed to use global variables and I have to make function calls and use of call by value parameters.
    My current code has many errors I believe and I think i fundamentally do not understand what is going on here, so any help would be great.

    2. Relevant equations


    3. The attempt at a solution
    Code (Text):

    #include <stdio.h>
    #include <math.h>
    Calculation(float c1, float c2, float c3, float f1, float f2, float f3);

    int main()
    {

    float c1, c2, c3, f1, f2, f3;
    float new1, new1, new3;
    float newa, newb, newc;

    printf("Please type in three temperatures in fahrenheit");
    scanf("%f %f %f", &f1, &f2, &f3);
    new1 = calc_celcius(f1);
    new2 = calc_celcius(f2);
    new3 = calc_celcius(f3);

    printf("The converted temperatures are: \t %.2f %.2f %.2f", new1, new2, new3);

    printf("Please type in three temperatures in celcius");
    scanf("%f %f %f", &c1, &c2, &c3);
    newa = calc_fah(c1);
    newb = calc_fah(c2);
    newc = calc_fah(c3);

    printf("The converted temperatures are: \t %.2f %.2f %.2f", newa, newb, newc);

    return 0;

    }

    float calc_celcius(float f1, float f2, float f3);

    {

    float new1 = ((f1 - 32) * .55);
    float new2 = ((f2 - 32) * .55);
    float new3 = ((f3 - 32) * .55);

    return(calc_celius);

    }

    float calc_fahr(float c1, float c2, float c3);

    {

    float newa = (c1 * 1.8) + 32;
    float newb = (c2 * 1.8) + 32;
    float newc = (c3 * 1.8) + 32;

    return(calc_fahr);

    }
     
    My questions:
    1) How do i properly configure my prototype function?
    2) How do i properly declare variables locally or using parameters?
    3) Is there anything im missing

    Thank you very much !
     
  2. jcsd
  3. Oct 20, 2015 #2

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    In your function calc_celcius, you should subtract 32. from the fahrenheit temperature, rather than 32, since this temp. is declared float. Also, the conversion 5. / 9. should be used in place of 0.55, since 5/9 is a non-terminating decimal, and using 0.55 cuts off precision of your result at two decimal places.

    In your function calc_fahr, similarly, you should add 32. rather than 32

    The correct name for the temperature scale is celsius with two s's. I don't know how celcius with two c's got started, probably the same place ect. comes from, rather than the correct etc. etc. = et cetera, which is Latin for "and other things".
     
  4. Oct 20, 2015 #3

    Mark44

    Staff: Mentor

    In addition to what SteamKing said, your calc_celsius() function should NOT calculate three Celsius temperatures at a time. The function should take a single Fahrenheit temperature and return the corresponding Celsius temperature.

    Also, this is not how functions return a value in C:
    Code (C):

    float calc_celcius(float f1, float f2, float f3);
    {
       // ...
       return(calc_celius);
    }
    In C, the name of a function evaluates to the location in memory where the code for the function is stored. The statement
    Code (Text):
    return(calc_celsius);
    is returning a memory address, not the computed temperature value.

    Please change the names in your program to the correct spelling -- celsius.
     
    Last edited: Oct 21, 2015
  5. Oct 22, 2015 #4
    Ok, i have changed the typo in my code. But still I am having issues with my code compiling.

    Code (Text):

    #include <stdio.h>
    #include <math.h>
    float calc_celsius( float );
    float calc_fahr( float );

    void printAll();

    int main()
    {

    float c1, c2, c3, f1, f2, f3;

    printf("Please type in three temperatures in fahrenheit \n");
    scanf("%f %f %f", &f1, &f2, &f3);
    printf("Please type in three temperatures in celsius \n");
    scanf("%f %f %f", &c1, &c2, &c3);

    return 0;

    }

    float calc_celsius( float fahr )
    {
      float celc = (fahr - 32) *  9/5;
      return celc;
    }

    float calc_fahr(float celc)

    {

    return celc * 1.8 + 32;

    }

    void printAll() {
    float calc_celsius( float celc);
    float calc_fahr( float fahr );

    printf("Fahrenheit \t | Celsius \n");
    printf("***************************** \n");
    printf("%.2f \t\t %.2f \n", f1, calc_celsius(f1));
    printf("%.2f \t\t %.2f \n", f2, calc_celsius(f2));
    printf("%.2f \t\t %.2f \n", f3, calc_celsius(f3));

    printf("The Temperature Conversions from Celsius to Fahreinheit are \n");
    printf("Celsius \t | Fahrenheit \n");
    printf("**************************** \n");
    printf("%.2f \t\t %.2f \n", c1, calc_fahr(c1));
    printf("%.2f \t\t %.2f \n", c2, calc_fahr(c2));
    printf("%.2f \t\t %.2f \n", c3, calc_fahr(c3));


    }
     
    Here is my new code; In my assignment I am supposed to have a function that is dedicated to printing the results of my function. How can i declare functions calc_celsius and calc_fahr inside of printAll ? Is this even the right way of going about things?
    Error logs say that everything inside of printAll is not declared(f1, f2, f3, c1, c2, c3) etc


    Edit: I mean how can i access variables in the main function for printAll ?


    Thanks .
     
  6. Oct 22, 2015 #5
    Nvm i got it. It took me a while to understand this stuff, does anyone have any tips on where i can get definitive info about C? It feels like im just learning by trial and error which i dont really like.
    Like a book for somewhat beginners(I guess i am still at intro level)?
     
  7. Oct 22, 2015 #6

    Mark44

    Staff: Mentor

    Isn't there a textbook suggested/required for your class? If not, this one isn't too bad -- "C Primer Plus" Sixth Ed., by Stephen Prata (https://www.amazon.com/Primer-Plus-...3/ref=tmm_pap_title_0?_encoding=UTF8&qid=&sr=).

    What did you get for the final version of your program? I'm sure we could give you some tips for improving it.
     
  8. Oct 22, 2015 #7

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    It looks like you're doing the same conversion from fahrenheit to celsius as celsius to fahrenheit. Check the celsius to fahrenheit conversion formula.
     
  9. Oct 27, 2015 #8
    calc_celsius is meant to convert a celsius temperature in to fahrenheit, which i think i didnt clarify. That is my bad

    Here was my old code: (My teacher told me to use lots of comments but i think they are very annoying...)
    Code (Text):
     
    #include <stdio.h>
    #include <math.h>
    float calc_celsius( float ); // prototype declarations
    float calc_fahr( float ); // and again
    float printAll(float f1, float f2, float f3, float c1, float c2, float c3); // last declaration

    int main()
    {

    float c1, c2, c3, f1, f2, f3; // declaring input variables

    printf("Please type in three temperatures in fahrenheit \n");
    scanf("%f %f %f", &f1, &f2, &f3); // storing them inside of main
    printf("Please type in three temperatures in celsius \n");
    scanf("%f %f %f", &c1, &c2, &c3); // and again storing

    printAll(f1, f2, f3, c1, c2, c3); // calling printAll function for the previously stored variables

    return 0;

    }

    float calc_celsius( float fahr ) // function definition
    {
      float celc = (fahr - 32) * 5/9; // function and formula that is used to convert fahrenheit to celsius
      return celc; // returns the value back to main
    }


    float calc_fahr(float celc) // function definition

    {

    return celc * 1.8 + 32; // function and formula that is used to convert celsius to fahrenheit, and returns the value to main

    }

    float printAll(float f1, float f2, float f3, float c1, float c2, float c3) { // parameters here include main function variables, so it can be used later on

    printf("Fahrenheit \t | Celsius \n");
    printf("***************************** \n");
    printf("%.2f \t\t %.2f \n", f1, calc_celsius(f1)); // calc_celsius is then called here in this statement, which converts f1(first input value from the user) in to celsius
    printf("%.2f \t\t %.2f \n", f2, calc_celsius(f2)); // and again, same thing is repeated with the 2nd value from the user
    printf("%.2f \t\t %.2f \n", f3, calc_celsius(f3)); // and lastly the third value from the user is converted to celsius

    printf("The Temperature Conversions from Celsius to Fahreinheit are \n");
    printf("Celsius \t | Fahrenheit \n");
    printf("**************************** \n");
    printf("%.2f \t\t %.2f \n", c1, calc_fahr(c1)); // calc_fahr is called in this line so that c1(first input value from user that is in celsius) is converted into fahrenheit
    printf("%.2f \t\t %.2f \n", c2, calc_fahr(c2)); // and again
    printf("%.2f \t\t %.2f \n", c3, calc_fahr(c3)); // and again

    }

     /*

     printAll calls the functions calc_celsius and calc_fahr in order to print out the needed temperatures. Main function simply calls printAll after the user finishes typing his input, and from there the user is
     is able to see the converted temperatures */
     
    now my question is, how can i use pointers instead of call by value? would this code suffice? (it does not compile)
    Code (Text):

    printf("Please type in three temperatures in fahrenheit");
    scanf("%f %f %f",&f1,&f2,&f3);


    printf("Please type in three temperatures in celcius");
    scanf("%f %f %f",&c1,&c2,&c3);

    calc_celsius(&f1,&f2,&f3)
    printf("The converted temperatures are: \t %.2f %.2f %.2f", f1, f2, f3 );

    calc_fahr(&c1,&c2,&c3))
    printf("The converted temperatures are: \t %.2f %.2f %.2f", c1, c2, c3);


    return0;

    }

    void calc_celsius(float*f1,float*f2,float*f3);

    {

    *f1 =(((*f1)-32)*.55);*f2 =(((*f2)-32)*.55);*f3 =(((*f3)-32)*.55);

    }

    void calc_fahr(float*c1,float*c2,float*c3)

    {

    *c1 =((*c1)*1.8)+32;*c2 =((*c2)*1.8)+32;*c3 =((*c3)*1.8)+32;

    }
    I wasn't sure if i was to not have 3 temperatures calculated at the same time since im using pointers(i thought it was spuposed to change stored values for each variable in the main function) or follow the same logic as my initial code.

    and am i calling my functions correctly?

    Thanks
     
  10. Oct 27, 2015 #9

    Mark44

    Staff: Mentor

    I don't know whether you realize this, but in C, 5/9 is equal to zero, due to the difference between integer division and floating point division. Your code probably works because of some casting going on behind the scenes, but you should not rely on this. It would be much better to write the fraction as 5.0/9.0 or 5.0f/9.0f.


    From the user's perspective, this is bad practice. It's much better to ask for one temperature at a time.

    Why is your function calculating all three temperatures at a time? Also, the variables f1, f2, and f3, which represent Fahrenheit temperatures, will be overwritten by their Celsius equivalents.
    I would write this function's header like so:
    Code (C):
    void calc_celsius(float temp_f, float * temp_c)
    After the function returns, the variable temp_c will be set to the equivalent Celsius temperature.

    Same idea for the other conversion function.
    .55 is not very precise. It's better to use 5.0f/9.0f.
     
  11. Oct 27, 2015 #10
    ok so i adjusted my new code to be similar to my old one a bit and here it is:
    Code (Text):

    #include <stdio.h>
    #include <math.h>
    float calc_celsius( float fahr, float *celc );
    float calc_fahr( float celc, float *fahr );
    float printAll(float f1, float f2, float f3, float c1, float c2, float c3); // last declaration

    int main()
    {

    float c1, c2, c3, f1, f2, f3;

    printf("Please type in three temperatures in fahrenheit \n");
    scanf("%f %f %f", &f1, &f2, &f3);
    printf("Please type in three temperatures in celsius \n");
    scanf("%f %f %f", &c1, &c2, &c3);

    printAll(f1, f2, f3, c1, c2, c3);

    return 0;

    }

    float calc_celsius( float fahr, float *celc )
    {
    *celc = (fahr - 32) * 5.0/9.0;
      return *celc;
    }


    float calc_fahr(float celc, float *fahr)

    {

    *fahr = (celc + 32) * 1.8;
    return;
    }

    float printAll(float f1, float f2, float f3, float c1, float c2, float c3) {

    printf("Fahrenheit \t | Celsius \n");
    printf("***************************** \n");
    printf("%.2f \t\t %.2f \n", f1, calc_celsius(&f1));
    printf("%.2f \t\t %.2f \n", f2, calc_celsius(&f2));
    printf("%.2f \t\t %.2f \n", f3, calc_celsius(&f3));

    printf("The Temperature Conversions from Celsius to Fahreinheit are \n");
    printf("Celsius \t | Fahrenheit \n");
    printf("**************************** \n");
    printf("%.2f \t\t %.2f \n", c1, calc_fahr(&c1));
    printf("%.2f \t\t %.2f \n", c2, calc_fahr(&c2));
    printf("%.2f \t\t %.2f \n", c3, calc_fahr(&c3));

    }

     
    and these are the errors i get
    Code (Text):

    \asn44.c||In function 'printAll':|
    \asn44.c|42|error: incompatible type for argument 1 of 'calc_celsius'|
    \asn44.c|23|note: expected 'float' but argument is of type 'float *'|
    \asn44.c|42|error: too few arguments to function 'calc_celsius'|
    \asn44.c|23|note: declared here|
    \asn44.c|43|error: incompatible type for argument 1 of 'calc_celsius'|
    \asn44.c|23|note: expected 'float' but argument is of type 'float *'|
    \asn44.c|43|error: too few arguments to function 'calc_celsius'|
    \asn44.c|23|note: declared here|
    \asn44.c|44|error: incompatible type for argument 1 of 'calc_celsius'|
    \asn44.c|23|note: expected 'float' but argument is of type 'float *'|
    \asn44.c|44|error: too few arguments to function 'calc_celsius'|
    \asn44.c|23|note: declared here|
    \asn44.c|49|error: incompatible type for argument 1 of 'calc_fahr'|
    \asn44.c|30|note: expected 'float' but argument is of type 'float *'|
    \asn44.c|49|error: too few arguments to function 'calc_fahr'|
    \asn44.c|30|note: declared here|
    \asn44.c|50|error: incompatible type for argument 1 of 'calc_fahr'|
    \asn44.c|30|note: expected 'float' but argument is of type 'float *'|
    \asn44.c|50|error: too few arguments to function 'calc_fahr'|
    \asn44.c|30|note: declared here|
    \asn44.c|51|error: incompatible type for argument 1 of 'calc_fahr'|
    \asn44.c|30|note: expected 'float' but argument is of type 'float *'|
    \asn44.c|51|error: too few arguments to function 'calc_fahr'|
    \asn44.c|30|note: declared here|
    ||=== Build failed: 12 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
     
    i dont understand these errors..? why is it telling me incomptaible types and too few arguments?
     
  12. Oct 27, 2015 #11

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    One thing I don't understand is you declare these functions before the main program:
    Code (Text):

    float calc_celsius( float fahr, float *celc );
    float calc_fahr( float celc, float *fahr );
    float printAll(float f1, float f2, float f3, float c1, float c2, float c3); // last declaration
     
    And then you declare them again after the main program. What's the point of doing this? Most compilers get confused if there are multiple declarations of the same function.
     
  13. Oct 27, 2015 #12

    Mark44

    Staff: Mentor

    Unless I'm missing something, what you're calling declarations after main() are actually definitions of these functions. The declarations (AKA function prototypes) are at the top.

    The main problem I see is that the functions are declared and defined with two arguments, but are called with only one. Here is an example:
    Code (C):
    float calc_celsius( float fahr, float *celc );
    .
    .
    .
    // In printAll()
    printf("%.2f \t\t %.2f \n", f1, calc_celsius(&f1));
    The call to calc_celsius should look like this:
    Code (C):

    ... calc_celsius(f1, &c1)...
    All of the calls to calc_celsius() need to be fixed, and all of the calls to calc_fahr() need a similar fix.

    In addition, calc_Xxx() doesn't return a usable value (both should return void), so it is an error to have it as an argument in printf(). When it returns, the value at the address specified in the call to calc_Xxx() will be set to a value.

    The declarations (prototypes) and definitions should look like this:
    Code (Text):
    void calc_celsius(float fahr, float * cels); // Declaration
    .
    .
    .
    void calc_celsius(float fahr, float * cels)   // Definition
    {
       // Body of function
    }
    Note that I abbreviated Celsius as cels.
     
  14. Oct 28, 2015 #13
    Ok so i got the new program to work with pointers finally. Here it is
    Code (Text):

    #include <stdio.h>
    #include <math.h>
    void calc_celsius( float fahr, float *cels );
    void calc_fahr( float cels, float *fahr );
    void printAll(float f1, float f2, float f3, float c1, float c2, float c3);

    int main()
    {

    float c1, c2, c3, f1, f2, f3;

    printf("Please type in three temperatures in fahrenheit \n");
    scanf("%f %f %f", &f1, &f2, &f3);
    printf("Please type in three temperatures in celsius \n");
    scanf("%f %f %f", &c1, &c2, &c3);

    printAll(f1, f2, f3, c1, c2, c3);

    return 0;

    }

    void calc_celsius( float fahr, float *cels )
    {
    *cels = (fahr - 32.) * 5.0 / 9.0;
    }


    void calc_fahr(float cels, float *fahr)

    {

      *fahr = (cels * 1.8 + 32);
    }

    void printAll(float f1, float f2, float f3, float c1, float c2, float c3) {

    float cels, fahr;

    printf("Fahrenheit \t | Celsius \n");
    printf("***************************** \n");
      calc_celsius(f1, &cels);
    printf("%.2f \t\t %.2f \n", f1, cels);
      calc_celsius(f2, &cels);
    printf("%.2f \t\t %.2f \n", f2, cels);
      calc_celsius(f3, &cels);
    printf("%.2f \t\t %.2f \n", f3, cels);

    printf("The Temperature Conversions from Celsius to Fahreinheit are \n");
    printf("Celsius \t | Fahrenheit \n");
    printf("**************************** \n");
      calc_fahr(c1, &fahr);
    printf("%.2f \t\t %.2f \n", c1, fahr);
      calc_fahr(c2, &fahr);
    printf("%.2f \t\t %.2f \n", c2, fahr);
      calc_fahr(c3, &fahr);
    printf("%.2f \t\t %.2f \n", c3, fahr);

    }


     
    but how can i use global variables instead of using any function calls ?

    i have this code which compiles fine, but it does not calculate any of my temperatures. All my outputs return as 0
    Code (Text):

    #include <stdio.h>
    #include <math.h>
    int calc_celsius();
    int calc_fahr();
    void printAll();

    float c1, c2, c3, f1, f2, f3;
    float fahr, cels;

    int main()
    {

    printf("Please type in three temperatures in fahrenheit \n");
    scanf("%f %f %f", &f1, &f2, &f3);
    printf("Please type in three temperatures in celsius \n");
    scanf("%f %f %f", &c1, &c2, &c3);

    printAll();

    return 0;

    }

    int calc_celsius()
    {

    cels = (fahr - 32) * 5/9;

    }


    int calc_fahr()

    {

     fahr = (cels * 1.8 + 32);

    }

    void printAll() {


    printf("Fahrenheit \t | Celsius \n");
    printf("***************************** \n");
    printf("%.2f \t\t %.2f \n", f1, calc_celsius(f1));
    printf("%.2f \t\t %.2f \n", f2, calc_celsius(f2));
    printf("%.2f \t\t %.2f \n", f3, calc_celsius(f3));

    printf("The Temperature Conversions from Celsius to Fahreinheit are \n");
    printf("Celsius \t | Fahrenheit \n");
    printf("**************************** \n");
    printf("%.2f \t\t %.2f \n", c1, calc_fahr(c1));
    printf("%.2f \t\t %.2f \n", c2, calc_fahr(c2));
    printf("%.2f \t\t %.2f \n", c3, calc_fahr(c3));


    }


     
    i feel like this is due to the printAll function and how im not using global variables properly.
     
  15. Oct 28, 2015 #14

    Mark44

    Staff: Mentor

    Informative comments are very useful to someone else reading your code, or even to you a few weeks or months after you've written your code.

    The first comment above is marginally OK, provided that you include useful comments with the definitions of these functions. The comments "// and again" and "// last declaration" are useless, as they provide no information to the reader.
    A comment should not restate the obvious. A better comment would state that c1, c2, c3 are intended to hold Celsius temperatures, and that f1, f2, and f3 are intended to hold Fahrenheit temperatures.
    What the line above is doing is reading three Fahrenheit temperatures from the console. As mentioned before, a better strategy, and one that is less confusing to a naive user, is to read these values one at a time. The only time that reading multiple values in a single scanf() call is reasonable is when you are taking input from a file, or possibly pulling data from a string (using sscanf() for example).
    Again, a comment should never merely restate what the code is doing. It's obvious that printAll() is being called. A better comment would be to state that all three F. temps and all three C. temps are to be printed.
     
  16. Oct 29, 2015 #15
    Ok thanks, its just my professor said add lots of comments so i commented practically everything in hopes she would give me full marks haha.. she also said all programs have to be in her exact lay out(so i can not have the user type in 3 values separately as she doesnt have it that way)
    but what about the second program?
    i am trying to make a program using only global variables and no call to functions. I can get the program to compile fine but all the answers are absolute jibberish???

    Code (Text):

    #include <stdio.h>
    #include <math.h>
    int calc_celsius();
    int calc_fahr();
    void printAll();

    float c1, c2, c3, f1, f2, f3;
    float fahr, cels;

    int main()
    {

    printf("Please type in three temperatures in fahrenheit \n");
    scanf("%f %f %f", &f1, &f2, &f3);
    printf("Please type in three temperatures in celsius \n");
    scanf("%f %f %f", &c1, &c2, &c3);

    printAll();

    return 0;

    }

    int calc_celsius()
    {

    cels = (fahr - 32) * 5/9;

    }


    int calc_fahr()

    {

     fahr = (cels * 1.8 + 32);

    }

    void printAll() {


    printf("Fahrenheit \t | Celsius \n");
    printf("***************************** \n");
    printf("%.2f \t\t %.2f \n", f1, f1);
    printf("%.2f \t\t %.2f \n", f2, f2);
    printf("%.2f \t\t %.2f \n", f3, f3);

    printf("The Temperature Conversions from Celsius to Fahreinheit are \n");
    printf("Celsius \t | Fahrenheit \n");
    printf("**************************** \n");
    printf("%.2f \t\t %.2f \n", c1, c1);
    printf("%.2f \t\t %.2f \n", c2, c2);
    printf("%.2f \t\t %.2f \n", c3, c3);


    }
     

    is it due to my printAll function - or is it because my other functions are returning incorrect values ?
     
  17. Oct 29, 2015 #16

    Mark44

    Staff: Mentor

    As I said earlier, it's not a good idea to input more than one variable at a time when you're taking input from the console. It's way too easy for a novice user to misunderstand what he needs to enter. I agree completely with your instructor.
    Why would you write a program using only globals? This is generally not a good idea. In the code you posted below, you are using functions. Do you mean you are using functions with no parameters? That, too, is a bad idea.
    Your calc_celsius() and calc_fahr() functions are returning int values, but you are storing these values in float variables.
     
  18. Oct 29, 2015 #17
    i changed that, and still my answers are jibberish
     
  19. Oct 29, 2015 #18
    Ok, i finally got it to work. But i just have a question as this is a guideline for my program
    "The first program should not use any global variables, must pass all input parameters using call-by-value parameters and must pass all function result parameters using callby-reference parameters."

    Did i not do this in my first program ? is this asking me to convert 3 temperatures at once individually? (which was my initial logic)
     
  20. Oct 29, 2015 #19

    SteamKing

    User Avatar
    Staff Emeritus
    Science Advisor
    Homework Helper

    I don't see anything in the guideline that requires you to throw multiple temperatures at the conversion routines at one time. As has been indicated above, doing so makes the program less flexible.
     
  21. Oct 29, 2015 #20

    Mark44

    Staff: Mentor

    You didn't do this in your first program that you showed in this thread.

    Your later attempt did satisfy this requirement: "pass all input parameters using call-by-value parameters and pass all function result parameters using callby-reference parameters."
    Here's a snippet of code that shows this:
    Code (C):

    void calc_celsius(float fahr, float * cels)   // Definition
    {
       // Body of function
    }
    The first parameter, fahr, is a call-by-value input parameter. The second parameter, cels, is a pointer, which is how C simulates call-by-reference parameter passing.

    No, not at all. See my explanation above.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: C program using functions to convert Fahrenheit and Celsius
Loading...