Converting Fahrenheit & Celsius: A C Programming Guide

Click For Summary

Discussion Overview

The discussion revolves around writing a C program for converting temperatures between Fahrenheit and Celsius. It includes technical aspects of programming, debugging, and compiler behavior.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant requests assistance in writing a C program for temperature conversion.
  • Another participant suggests that the main definition of the program may be incorrect and recommends using floating point numbers instead of integers for accuracy.
  • A different participant questions the original poster about the indications of issues with their compiler and asks for the specific compiler being used.
  • It is pointed out that a missing semicolon in the printf statement could lead to errors, and that integer division could cause inaccuracies in calculations, recommending the use of floating point numbers instead.
  • Concerns are raised about the lack of a return type for the main function, which may lead to compiler warnings or errors.
  • One participant encourages the original poster to clarify what they mean by "something is wrong" with their compiler.

Areas of Agreement / Disagreement

Participants express differing views on the correctness of the original program and the issues with the compiler. There is no consensus on the specific problems or solutions presented.

Contextual Notes

Limitations include potential misunderstandings of compiler behavior, the need for clarity on definitions, and unresolved issues regarding program structure and syntax.

Who May Find This Useful

Individuals interested in C programming, particularly those working on temperature conversion algorithms or debugging compiler issues.

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"?
 

Similar threads

Replies
11
Views
4K
  • · Replies 18 ·
Replies
18
Views
11K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
86
Views
3K
  • · Replies 39 ·
2
Replies
39
Views
6K
Replies
38
Views
4K
  • · Replies 24 ·
Replies
24
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 42 ·
2
Replies
42
Views
4K