# Thread: Converting Farenheit to Celcius: - Turbo C

1. ## 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

2. Code:
`(5/9) = 0`
Code:
`(5.0/9.0) = .5555555`
Be careful about integer division. It always rounds down.

3. 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();
}```

4. First of all, i think your formula is upside down.

Second, your printf should be

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

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. ## thank you

it worked well thanks

6. > 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.

7. IOW, lose Turbo C, and get something like MinGW, LCC, Borland's somewhat newer stuff, or Microsoft's Visual stuff.

8. but thats what we used in our basic programming class

thanks for the advice

9. Originally Posted by EdwardElric
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. 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:
Originally Posted by Govalant
First of all, i think your formula is upside down.
Oops, didn't see that. X_X

11. > 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?

12. 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