This is my program for a sauna. It is a Swedish sauna meant to only understand Celsius, but the user can only understand Fahrenheit, so when the user inputs Fahrenheit, it is converted to Celcius. Afterwards, the Celsius is rounded to an even value when presented to the user, to get rid of all the decimals from the conversion.
class Program
{
static void tempCheck(double temperature)
{
if (temperature < 0)
{
Console.WriteLine("The sauna has now become a freezer, \nCelcius: {0}", Math.Round(temperature));
Console.WriteLine();
}
else if (temperature < 73)
{
Console.WriteLine("This temperature is too low for sauna use, \nCelcius: {0}", Math.Round(temperature));
Console.WriteLine();
}
else if (temperature > 100)
{
Console.WriteLine("You will be boiled alive if you use the sauna, \nCelcius: {0}", Math.Round(temperature));
Console.WriteLine();
}
else if (temperature > 77)
{
Console.WriteLine("This heat will scald you, please lower the temperarture, \nCelcius: {0}", Math.Round(temperature));
Console.WriteLine();
}
else if (temperature == 75)
{
Console.WriteLine("Perfect heat for sauna!");
Console.WriteLine();
}
else
Console.WriteLine("This temperature is adequate for sauna use! \nCelcius: {0}", Math.Round(temperature));
}
public static double FahrToCels(int fahr)
{
double fahrenheit = (5.0 / 9.0) * (fahr - 32);
return fahrenheit;
}
static void Main(string[] args)
{
double temperature = 0;
Console.WriteLine("Enter a desired temperature between 73 och 77 celcius");
do
{
try
{
int fahrenheit = int.Parse(Console.ReadLine());
Console.WriteLine(temperature);
double celcius = FahrToCels(fahrenheit);
Console.WriteLine(celcius);
temperature = temperature + celcius;
tempCheck(temperature);
}
catch (FormatException)
{
Console.WriteLine("Please only enter whole numbers, no decimals");
}
catch
{
Console.WriteLine("Error");
}
} while (temperature < 73 || temperature > 77);
}
}
}
Celcius
class so the code is handling "celsius temperatures" not mere integer values. So notstatic void tempCheck(double temperature)
, butstatic void tempCheck(Celsius temperature)
\$\endgroup\$