Skip to content
ExamplesEspañolWorkspace →

Temperature Converter

Converts degrees Celsius to Fahrenheit and Kelvin.

Level
Beginner
Concepts:
Input & output
Variables
Math
Open in Codoritmo

Run, change and debug this example in your browser.

What you'll learn

You work with Real variables and the <- assignment operator. The formulas use *, / and + just like in math class.

Code

temperature.psc · 9 lines
Algoritmo ConversorTemperatura    Definir celsius, fahrenheit, kelvin Como Real    Escribir "Temperatura en grados Celsius:"    Leer celsius    fahrenheit <- celsius * 9 / 5 + 32    kelvin <- celsius + 273.15    Escribir celsius, " °C equivalen a ", fahrenheit, " °F"    Escribir celsius, " °C equivalen a ", kelvin, " K"FinAlgoritmo

Flowchart

Each block in the flowchart matches one instruction in the code.

Algoritmo ConversorTemperaturaAlgoritmo ConversorTemperaturaAlgoritmo ConversorTemperaturaDefinir celsius, fahrenheit, kelvin Como RealDefinir celsius, fahrenheit,kelvin Como RealEscribir "Temperatura en grados Celsius:"Escribir "Temperatura engrados Celsius:"Leer celsiusLeer celsiusfahrenheit <- celsius * 9 / 5 + 32fahrenheit <- celsius * 9 / 5+ 32kelvin <- celsius + 273.15kelvin <- celsius + 273.15Escribir celsius, " °C equivalen a ", fahrenheit, " °F"Escribir celsius, " °Cequivalen a ", fahrenheit, "°F"Escribir celsius, " °C equivalen a ", kelvin, " K"Escribir celsius, " °Cequivalen a ", kelvin, " K"FinAlgoritmoFinAlgoritmo

Sample run

This is what the program shows when it runs. The answers typed by the user are highlighted.

Temperatura en grados Celsius:User answer: 2525 °C equivalen a 77 °F25 °C equivalen a 298.15 K

Challenge

Go the other way: ask for Fahrenheit and convert it to Celsius.

Show hint

Reverse the formula: subtract 32, then multiply by 5 / 9.

Open in Codoritmo
  • Fibonacci Sequence

    Prints the first terms of the Fibonacci sequence.

    Beginner
  • Hello World

    Your first algorithm: print a couple of messages on screen.

    Beginner
  • Body Mass Index

    Computes your BMI and classifies it as underweight, normal and so on.

    Intermediate