Converting Farenheit to Celcius: - Turbo C

This is a discussion on Converting Farenheit to Celcius: - Turbo C within the C Programming forums, part of the General Programming Boards category; hi i am a newbie in programming C and just learning the basics as of now: converting Celsius to Farenheit ...

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    19

    Converting Farenheit to Celcius: - Turbo C

    hi i am a newbie in programming C and just learning the basics as of now:
    converting Celsius to Farenheit
    and im using Turbo C btw:

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    main()
    {
    float C;
    float F;
    clrscr();
    printf ("Type a value of the Celsius: ");
    scanf ("&#37;f",&C);
    F = (5/9)*(C - 32);
    printf ("%2f",&F);
    getch();
    }
    the output of the program is 0.000000
    Last edited by EdwardElric; 07-21-2007 at 11:17 AM.

  2. #2
    Captain - Lover of the C
    Join Date
    May 2005
    Posts
    341
    Code:
    (5/9) = 0
    Code:
    (5.0/9.0) = .5555555
    Be careful about integer division. It always rounds down.
    Don't quote me on that... ...seriously

  3. #3
    Registered User
    Join Date
    Jul 2007
    Posts
    19
    tried that and the signed float function but still doesnt work

    Code:
    #include <stdio.h>
    #include <conio.h>
    
    main()
    {
    signed float C;
    signed float F;
    clrscr();
    printf ("Type a value for the Celsius: ");
    scanf ("&#37;f",&C);
    F = (5.0/9.0)*(C-32.0);
    printf ("the Farenheit is %f",&F);
    getch();
    }
    Last edited by EdwardElric; 07-21-2007 at 11:27 AM.

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    58
    First of all, i think your formula is upside down.

    Second, your printf should be

    Code:
    printf ("the Farenheit is &#37;f",F);
    instead of

    Code:
    printf ("the Farenheit is %f",&F);
    printf just prints teh value in the screen, it needs the value, there's no need to pass the address of the variable.



    And didn't you play argentum?

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    19

    Thumbs up thank you

    it worked well thanks

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > and im using Turbo C btw:
    Are you using DOS then?

    Because this is museum software, which means if your OS is something like XP and your machine is a GHz+ Pentium with RAM to match, you now have a Ferrari powered by an elastic band.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    IOW, lose Turbo C, and get something like MinGW, LCC, Borland's somewhat newer stuff, or Microsoft's Visual stuff.

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    19
    but thats what we used in our basic programming class

    thanks for the advice

  9. #9
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Quote Originally Posted by EdwardElric View Post
    but thats what we used in our basic programming class

    thanks for the advice
    Erm, why? Ask your lecturer, I'm interested to know.

  10. #10
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902

    Exclamation

    Code:
    printf ("Type a value for the Celsius: ");
    ...
    printf ("the Farenheit is &#37;f",&F);
    Your printf()s and formula don't match. You're using F = (5.0/9.0)*(C-32.0) which is the formula for finding Celsius from Fahrenheit. Your program is backwards.

    Also, don't use conio.h - it's not portable, and you won't find it on modern compilers. (This means clrscr() is out) Let your program do one thing, and do it well. Temperature conversion. Don't worry about the screen. Who says there even is a screen?
    "signed float" - don't use signed. My compiler (gcc) throws errors for that. Using a double instead of a float will also gain you more precision.

    Be careful about integer division. It always rounds down.
    It always truncates. 5 / 2 = 2, but -5 / 2 is -2, not -3.

    EDIT:
    Quote Originally Posted by Govalant
    First of all, i think your formula is upside down.
    Oops, didn't see that. X_X
    Last edited by Cactus_Hugger; 07-21-2007 at 11:07 PM.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    > but thats what we used in our basic programming class
    Are you paying money for this course?

    What if the course was something like "car mechanics" and the tutor decided to base all his work on the original Model-T Ford.

    All very well, but when you get back to the real world, you suddenly find that 99&#37; of your skills are, how shall I put this, USELESS. Sure you might be OK with the basics of say putting air in the tyres, but as soon as you open the hood, it's "hello, confused now".

    Would you be annoyed that the tutor had taken your money, and wasted your time teaching you some massively out of date skills leaving you pretty much at the start line?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Registered User
    Join Date
    Jul 2007
    Posts
    19
    yeah i know its up to date but thats what our university is using... i dunno why i think its because its basic programming... yeah im a CompE major btw
    thanks for all the advices

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. converting struct to tables in turbo c++
    By geft in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2008, 07:44 AM
  2. Remember Turbo? It is comming back
    By Mario F. in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2006, 01:26 PM
  3. sorry to bother all but please help me :)
    By cam123666 in forum C++ Programming
    Replies: 5
    Last Post: 02-04-2005, 06:24 PM
  4. Why is this program converting to integers
    By 3DPhreak in forum C++ Programming
    Replies: 3
    Last Post: 05-31-2004, 09:44 AM
  5. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 12:51 PM

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