Amerikanen i bastun
Hej, behöver lite hjälp med min kod får den inte riktigt att fungera, vill först få den att fungera med INT tal. sen tänkte jag lägga till double samt try och catch.Jag försöker lista ut hur jag ska kunna göra så att loopen sparar värdet som användaren mattar in.
Mvh illiam
som killen nämner här:
"Den första gissningen kommer alltså aldrig användas för att kontrollera om loopen ska fortsätta eller ej, eftersom du alltid läser in ett nytt värde i slutet av loopen.
I det här fallet så behöver du inte ha inläsning på flera ställen i koden, utan det räcker med att läsa in värdet i början av loopen. D.v.s. du bör inte ha "första gissningen" som ett specialfall utanför loopen, utan hantera alla gissningar på samma sätt inne i loopen istället."
class MainClass
{
public static int FahrToCels(int fahr)
{
int celsius = (fahr - 32) * 5 / 9;
return celsius;
}
public static void Main(string[] args)
{
Console.WriteLine("Welcome");
Console.WriteLine("Enter the temperatur of the sauna in farenheit");
int fahr = int.Parse(Console.ReadLine());
int celsius = FahrToCels(fahr);
do
{
if (celsius < 73)
{
Console.WriteLine(" The current temperature is " + celsius + " which is to cold");
Console.WriteLine("Please raise the temperature in the sauna for comfort: ");
}
else if (celsius > 77)
{
Console.WriteLine(" The current temperature is " + celsius + " which is to hot");
Console.WriteLine("Please lower the temperature in the sauna for comfort: ");
}
else if (celsius == 75)
{
Console.WriteLine(" The current temperature is " + celsius + " which is perfect: ");
}
else
{
Console.WriteLine("You can no enjoy the Sauna,but for future refernce the optimal temp is 100 deggres celsius ");
}
} while (celsius <= 73 || celsius >= 77);
Console.WriteLine(" Program terminated ");
}
}
}