October 2017
Beginner
318 pages
7h 26m
English
We're going to use Celsius as our first point of conversion in all cases, so if our user has inputted a Celsius value, we can just go ahead and break out of this case because the value of inputValue is already OK with us:
switch(inputType)
{
case 'F':
case 'C':
break;
case 'K':
default:
System.exit(1);
What if the user has given us a Fahrenheit value? Well, let's scroll to the top of the code; you'll see that we have an explicit conversion from Fahrenheit to Celsius:
// F to C: ((t-32.0f)*5.0f)/9.0f // C to K: t+273.15f // K to F: (((t-273.15f)*9.0f)/5.0f)+32.0f
We can take the preceding block of code, which I've made pretty Java-friendly, and just change the value of this input variable to the conversion statement run on its ...
Read now
Unlock full access