Converting Fahrenheit & Celsius: A C Programming Guide

AI Thread Summary
To write a C program for converting between Fahrenheit and Celsius, it's crucial to address several key points. The main function definition may be incorrect, and using floating-point numbers instead of integers is essential for accurate calculations. The tests for input characters 'c' and 'f' may not function as intended. Additionally, ensure that the printf statement is correctly formatted, including a semicolon at the end. It's important to avoid integer division, as using expressions like 5 / 9 will yield incorrect results; instead, use 5.0 / 9.0 to ensure floating-point division. Lastly, check that the main function has a defined return type, and clarify any issues with the compiler being used.
queenspublic
Messages
59
Reaction score
0
Okay. I need to write a C program to convert between fahrenheit and celsius degrees.
 
Last edited:
Technology news on Phys.org
Have you asked the computer?
Off the top of my head;
The main definition is wrong - it might compile but it's wrong.
You probably want to use floating point numbers rather than integers
Your tests for 'c' and 'f' don't do what you think they do
 
What is the indication leading you to believe there is somethig wrong with your compiler? Also, which compiler product are you using?
 
The line beginning with "printf("%d degrees celsius" is missing a semicolon.

You should not say something like 5 / 9 in C. Division in an integer expression will round down, such that 5 / 9 = 0. Say something more like 5.0 / 9.0, or promote "degrees" to a float, so that the compiler knows to use floating point math.

Also maybe some compilers will complain that there is no return type for main().

You should try to get your compiler working. As potential asks, what do you mean "something is wrong with it"?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top