New to C programming

This is a discussion on New to C programming within the C Programming forums, part of the General Programming Boards category; I just want to star by saying I'm not looking for any answers to my assignments, but just some help ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    New to C programming

    I just want to star by saying I'm not looking for any answers to my assignments, but just some help as to where to go next...

    Hi,

    I just started an Intro to C class 2 weeks ago and so far so good, but as a newbie
    to programming, it's is a little overwhelming at times. I was able to complete my first assignment without a problem, but my second one has me stumped...

    I need to write a program that converts 27 from degrees Fahrenheit (F) to degrees Celsius (c) using the formula below...

    C = (F - 32) /1.8

    I was hoping someone could point me in the right direction or show me an example using the formula above. Below is a program I wrote and wondering how I can add the formula to this?

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    8
    Do you know about scanf() and printf() ?

  3. #3
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    there's no program with that post...

    you have the formula, so it shouldn't be hard:
    use floats -

    Code:
    float C;
    float F = 27.0;
    
    C = (F-32)/1.8;
    then just prinf the value of C to the screen
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    21
    Code:
    #include <stdio.h>
    #include "genlib.h"
    #include "simpio.h"
    main()
    {
    int degrees_f, degrees_c;
    /* Input Phase */
    printf("This program converts degrees F to degrees C.\n");
    printf("Input the temperature in degrees Fahrenheit: ");
    degrees_f = GetInteger();
    /* Computation Phase */
    degrees_c = 5 / 9 * (degrees_f - 32);
    /* Output Phase */
    printf("%d degrees F is %d degrees C\n", degrees_f, degrees_c);
    }
    just change the formula.

  5. #5
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    > #include "genlib.h"
    > #include "simpio.h"

    WHY?? what are they?


    > int degrees_f, degrees_c;
    you need floats or doubles for percision!!!!
    Last edited by twomers; 02-14-2006 at 11:48 AM.

  6. #6
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    i agree with twomers - whats wrong with you guys!
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  7. #7
    Registered User
    Join Date
    Feb 2006
    Posts
    43
    Yeah seriously guys....he's asking for help, not for you to show off your knowledge.
    Either do what Richie T said, or since you only need the program to calculate what 27 is in F you can do it using this
    Code:
    printf("%f",(27-32)/1.8);
    which should simply display the value obtained when 32 is subtracted form 27 and then divided by 1.8. Admitedly this does not leave much room for flexibility, but if that is the only thing that needs to be calculated then why go for complexity.

  8. #8
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    Try searching the board: http://cboard.cprogramming.com/searc...earchid=325996

    The Fahrenheit-Celsius program or its opposite is a very common program.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  9. #9
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Location
    Cambridge, UK
    Posts
    1,682
    Quote Originally Posted by jcard71
    I just want to star by saying I'm not looking for any answers to my assignments, but just some help as to where to go next...

    Hi,

    I just started an Intro to C class 2 weeks ago and so far so good, but as a newbie
    to programming, it's is a little overwhelming at times. I was able to complete my first assignment without a problem, but my second one has me stumped...

    I need to write a program that converts 27 from degrees Fahrenheit (F) to degrees Celsius (c) using the formula below...

    C = (F - 32) /1.8

    I was hoping someone could point me in the right direction or show me an example using the formula above. Below is a program I wrote and wondering how I can add the formula to this?
    well, u can always serach the borad as what DWKs says. but here some of the tips that u can start with. u reqire some of these fucntion in order to go ahead with the soultion to the problem. u need scanf, printf. i dont know wheather u knnow how to use these fucntion. but here is syntax for those
    Code:
    printf("format specifier£, variables name);
    eg: printf("The Celsius %d", C);
    
    scanf("format specifier", address of the variables);
    eg: scanf("%d",&C);
    given any formula, it s easy to convert to a code. lets take a very simple example, for instance if u take a expression something like this (a + b) * (b * b + 2b), how do u go ahead to convert this into a C code

    the answer is just the same the only change is that u need to store the result in some place so that u can retain it back where ever u need it. the solution could look soemthing like this

    Code:
    result = (a + b) * (b * b + 2b);
    
    NOTE: result is just a varibale
    so u have rought ideia of how to covert a expression to a code. having this expression now C = (F - 32) /1.8 . how do u convert this expression. very simple its all the same but need to ready the value for the varibale F for u can literally insert it in the expression. here is a pesudo code for the problem.

    Code:
    declare a variable C
    read the value for F
    C = ( F * 32) / 1.8
    output the C

    ssharish2005

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21