Thursday, 22 July 2010

Temperature conversion - the logic

So what do we want to do when we convert between temperature scales? Clearly we either want to convert between Farenheit and Celsius or vice versa, so it would be good to be able choose between these two options.

So in our program we need two inputs called A and B, say; A will record what type of temperature conversion we want (for example, use 1 to indicate Farenheit to Celsius conversion and 2 to indicate the reverse) and B will record the temperature (in Celsius or Farenheit).

The logic behind a program would be:-

Input A (1 indicates F to C, 2 indicates C to F)
Input B (the temperature)
If A = 1
   Display (B-32)x(5/9) (the temperature in Celsius)
Else
   Display Bx(9/5)+32 (the temperature in Farenheit)
If-End

No comments:

Post a Comment