How to resolve the algorithm Temperature conversion step by step in the Clojure programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Temperature conversion step by step in the Clojure programming language

Table of Contents

Problem Statement

There are quite a number of temperature scales. For this task we will concentrate on four of the perhaps best-known ones: Kelvin, Celsius, Fahrenheit, and Rankine. The Celsius and Kelvin scales have the same magnitude, but different null points. The Fahrenheit and Rankine scales also have the same magnitude, but different null points. The Celsius/Kelvin and Fahrenheit/Rankine scales have a ratio of 5 : 9.

Write code that accepts a value of kelvin, converts it to values of the three other scales, and prints the result.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Temperature conversion step by step in the Clojure programming language

Source code in the clojure programming language

(defn to-celsius [k]
  (- k 273.15))
(defn to-fahrenheit [k] 
  (- (* k 1.8) 459.67))
(defn to-rankine [k] 
  (* k 1.8))
 
(defn temperature-conversion [k] 
  (if (number? k) 
    (format "Celsius: %.2f Fahrenheit: %.2f Rankine: %.2f" 
      (to-celsius k) (to-fahrenheit k) (to-rankine k)) 
    (format "Error: Non-numeric value entered.")))


  

You may also check:How to resolve the algorithm 15 puzzle game step by step in the C programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Burlesque programming language
You may also check:How to resolve the algorithm Hello world/Standard error step by step in the Scala programming language
You may also check:How to resolve the algorithm Combinations with repetitions step by step in the Perl programming language
You may also check:How to resolve the algorithm Sorting algorithms/Merge sort step by step in the Perl programming language