October 2017
Beginner
318 pages
7h 26m
English
We can do something similar for the Kelvin case. We don't have an explicit conversion from Kelvin to Celsius, but we do know how to convert Kelvin to Fahrenheit and then how to convert Fahrenheit to Celsius. So we can get away with doing something like the following:
switch(inputType)
{
case 'F':
inputValue = ((inputValue-32.0f)*5.0f)/9.0f;
break;
case 'C':
break;
case 'K':
inputValue = ((((((inputValue-273.15f)*9.0f)/5.0f)+32.0f) -
32.0f)*5.0f)/9.0f;
default:
System.exit(1);
}
In the preceding code, we converted our Kelvin value to a Fahrenheit value, surrounding it in parentheses, and did our Fahrenheit to Celsius conversion on that.
Now this is technically a functional line of code. If we run our program and enter a Kelvin ...
Read now
Unlock full access