Bifalgorithm post · Computer science one · Converting Units

How do you outline a C program that converts Fahrenheit to Celsius?

How do you outline a C program that converts Fahrenheit to Celsius? (Computer science one · Converting Units) — "Let’s write a program that will prompt the use…

Ideas in this flowchart

  • Programa para convertir una temperatura de Fahrenheit a Celsius
  • La conversión utiliza la fórmula C = (F − 32) · 5/9.
  • La estructura básica del programa incluye bibliotecas, una función main() y documentación.
  • Las directivas del preprocesador incluyen las bibliotecas estándar y de entrada/salida.
  • El código ejecutable se coloca dentro de la función main().
  • Un comentario documenta que el programa convierte temperaturas Fahrenheit a Celsius.
  • El comentario TODO indica que todavía falta implementar el programa.
  • El programa sigue cuatro pasos principales.
  • Solicitar al usuario una temperatura en Fahrenheit.
  • Leer el valor Fahrenheit desde la entrada estándar.
  • Calcular los grados Celsius mediante la fórmula de conversión.
  • Imprimir el resultado para informar al usuario.
  • Se necesitan variables fahrenheit y celsius para almacenar los valores de entrada y salida.
  • Ambas variables deben ser de tipo double para admitir valores fraccionarios.
  • La función printf() muestra el mensaje que solicita los grados Fahrenheit.
  • Para leer un valor double se utiliza el marcador %lf.
Feed/

How do you outline a C program that converts Fahrenheit to Celsius?

No cover

Channel

Computer science one

1 page

"Let’s write a program that will prompt the user to enter a temperature in degrees Fahrenheit and convert it to degrees Celsius using the formula C = ( F − 32) · 5 9. We begin with the basic program outline which will include preprocessor directives to bring in the standard library and the standard input/output library (we’ll need to prompt for input and print the result as output to the user). Further, we want our program to be executable, so we need to put our code into the main() function. Finally, we’ll document our program to indicate its purpose.\n\n#include <stdlib.h>\n\n#include <stdio.h>\n\n/**\n\n* This program converts Fahrenheit temperatures to\n\n* Celsius\n\n*/\n\nint main(int argc, char **argv) {\n\n//TODO: implement this\n\nreturn 0;\n\n}\n\nIt is common for programmers to use a comment along with a TODO note to themselves as a reminder of things that they still need to implement in a program. Let’s first outline the basic steps that our program will go through: 1. We’ll first prompt the user for input, asking them for a temperature in Fahrenheit. 2. Next we’ll read the user’s input, likely into a floating point number as degrees can be fractional. 3. Once we have the input, we can calculate the degrees Celsius by using the formula above. 4. Lastly, we will want to print the result to the user to inform them of the value.\n\nSometimes its helpful to write an outline of such a program directly in the code using comments to provide a step-by-step process. For example:\n\n#include <stdlib.h>\n\n#include <stdio.h>\n\n/**\n\n* This program converts Fahrenheit temperatures to\n\n* Celsius\n\n*/\n\nint main(int argc, char **argv) {\n\n//TODO: implement this\n\n//1. Prompt the user for input in Fahrenheit\n\n//2. Read the Fahrenheit value from the standard input\n\n//3. Compute the degrees Celsius\n\n//4. Print the result to the user\n\nreturn 0;\n\n}\n\nAs we read each step it becomes apparent that we’ll need a couple of variables: one to hold the Fahrenheit (input) value and one for the Celsius (output) value. It also makes sense that each of these should be double variables as we want to support fractional values. So at the top of our main() function, we’ll add the variable declarations: double fahrenheit, celsius; Each of the steps is now straightforward; we’ll use a printf() statement in the first step to prompt the user for input: printf(\"Please enter degrees in Fahrenheit: \"); In the second step, we’ll use the standard input to read the fahrenheit variable value from the user. Recall that we use the placeholder %lf for reading double values and"

Flowchart preview
👍
0
0 comments0 shares

Sign in to view and post comments.