Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class TemperatureConverter {
- public static double CelsiusToFahrenheit(string temperatureCelsius) {
- // Convert argument to double for calculations.
- double celsius = double.Parse(temperatureCelsius);
- // Convert Celsius to Fahrenheit.
- double fahrenheit = (celsius * 9 / 5) + 32;
- return fahrenheit;
- }
- public static double FahrenheitToCelsius(string temperatureFahrenheit) {
- // Convert argument to double for calculations.
- double fahrenheit = double.Parse(temperatureFahrenheit);
- // Convert Fahrenheit to Celsius.
- double celsius = (fahrenheit - 32) * 5 / 9;
- return celsius;
- }
- }
- public class TestTemperatureConverter : MonoBehaviour
- {
- // Start is called before the first frame update
- void Start()
- {
- Debug.Log("Please select the convertor direction");
- Debug.Log("1. From Celsius to Fahrenheit.");
- Debug.Log("2. From Fahrenheit to Celsius.");
- Debug.Log(":");
- string selection = Input.inputString;
- double F = 0, C = 0;
- switch (selection) {
- case "1":
- Debug.Log("Please enter the Celsius temperature: ");
- F = TemperatureConverter.CelsiusToFahrenheit(Input.inputString);
- Debug.Log("Temperature in Fahrenheit: " + F.ToString("F2"));
- break;
- case "2":
- Debug.Log("Please enter the Fahrenheit temperature: ");
- C = TemperatureConverter.FahrenheitToCelsius(Input.inputString);
- Debug.Log("Temperature in Celsius: " + C.ToString("F2"));
- break;
- default:
- Debug.Log("Please select a convertor.");
- break;
- }
- // Keep the console window open in debug mode.
- Debug.Log("Press any key to exit.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement