static void Main() { Console.WriteLine("Please select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); Console.Write(":"); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: Console.WriteLine("Please select a convertor."); break; } // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("Select the conversion you wish to do."); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. from Fahrenheit to Celsius."); string choice = Console.ReadLine(); if (choice == "1") { Console.Write("Please enter the Celsius temperature: "); string value = Console.ReadLine(); bool success = double.TryParse(value, out double celsius); //Could build in some safety for non-numeric values, but that's not the point of this example. Console.WriteLine("Temperature in Fahrenheit: " + TemperatureConverter.CelsiusToFahrenheit(celsius)); } else if (choice == "2") { Console.Write("Please enter the Fahrenheit temperature: "); string value = Console.ReadLine(); bool success = double.TryParse(value, out double fahrenheit); Console.WriteLine("Temperature in Celsius: " + TemperatureConverter.FahrenheitToCelsius(fahrenheit)); } else { Console.WriteLine("Invalid input, bye."); } Console.WriteLine("Press enter to exit."); Console.ReadLine(); }
public static void test() { Console.WriteLine("Please select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); Console.Write(":"); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: Console.WriteLine("Please select a convertor."); break; } }
protected void ConvertButton_Click(object sender, EventArgs e) { if (IsValid) { int startTemp = int.Parse(StartTempTextBox.Text); int endTemp = int.Parse(EndTempTextBox.Text); int temperaturStep = int.Parse(TemperaturstegTextBox.Text); if (!CelsiusToFahrnheit.Checked) { FirstTableHeaderCell.Text = "°F"; SecondTableHeaderCell.Text = "°C"; } for (int i = startTemp; i <= endTemp; i += temperaturStep) { var tRow = new TableRow(); TemperatureTable.Rows.Add(tRow); var tcell = new TableCell(); tRow.Cells.Add(tcell); tcell.Text = i.ToString(); tcell = new TableCell(); tRow.Cells.Add(tcell); tcell.Text = CelsiusToFahrnheit.Checked ? TemperatureConverter.CelsiusToFahrenheit(i).ToString() : TemperatureConverter.FahrenheitToCelsius(i).ToString(); } TemperatureTable.Visible = true; } }
static void Main() { System.Console.WriteLine("Please select the convertor direction"); System.Console.WriteLine("1. From Celsius to Fahrenheit."); System.Console.WriteLine("2. From Fahrenheit to Celsius."); System.Console.Write(":"); string selection = System.Console.ReadLine(); double F, C = 0; switch (selection) { case "1": System.Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheit(System.Console.ReadLine()); System.Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": System.Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(System.Console.ReadLine()); System.Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: System.Console.WriteLine("Please select a convertor."); break; } //This line waits for user to press key to terminate console Console.ReadLine(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); int s; RunCuntdown(3, out s); Console.WriteLine(s); Console.ReadLine(); Console.Write("Enter a dividend: "); int dividend = int.Parse(Console.ReadLine()); Console.Write("Enter a divisor: "); int divisor = int.Parse(Console.ReadLine()); int remainder; int result = Remainder(dividend, divisor, out remainder); Console.WriteLine("{0} / {1} = {2} with a remainder of {3}", dividend, divisor, result, remainder); Console.ReadLine(); Console.WriteLine("Please select the convertor direction"); Console.WriteLine("1. From Celsius to Fahrenheit."); Console.WriteLine("2. From Fahrenheit to Celsius."); Console.Write(":"); string selection = Console.ReadLine(); double F, C = 0; switch (selection) { case "1": Console.Write("Please enter the Celsius temperature: "); F = TemperatureConverter.CelsiusToFahrenheit(Console.ReadLine()); Console.WriteLine("Temperature in Fahrenheit: {0:F2}", F); break; case "2": Console.Write("Please enter the Fahrenheit temperature: "); C = TemperatureConverter.FahrenheitToCelsius(Console.ReadLine()); Console.WriteLine("Temperature in Celsius: {0:F2}", C); break; default: Console.WriteLine("Please select a convertor."); break; } // Keep the console window open in debug mode. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
public void FahrenheitToCelsius(decimal temperature, decimal expected) { // Arrange var temperatureConverter = new TemperatureConverter(); // Act var result = temperatureConverter.FahrenheitToCelsius(temperature); // Assert result.Should().Be(expected); }
private WeatherConditions GetResult(string json, Location location) { var weatherDto = JsonConvert.DeserializeObject <WeatherDto>(json); if (weatherDto?.query?.results?.channel?.item?.condition == null) { return(null); } var condition = weatherDto.query.results.channel.item.condition; // Icon.Code = 3200: not available if (condition.code == "3200") { return(null); } var url = weatherDto.query.results.channel.item.link; if (string.IsNullOrEmpty(url)) { url = "https://www.yahoo.com/?ilc=401"; } double temperatureF; double.TryParse(condition.temp, out temperatureF); var weatherConditions = new WeatherConditions() { Title = condition.text, Description = condition.text, TemperatureC = (int)Math.Ceiling(TemperatureConverter.FahrenheitToCelsius(temperatureF)), TemperatureF = (int)temperatureF, Icon = Icons.GetCssClass(condition.code), Location = location.City, CountryCode = location.CountryCode, UsesFahrenheit = location.UsesFahrenheit, Service = "Yahoo", ServiceUrl = url }; return(weatherConditions); }
private WeatherConditions GetResult(string json, Location location) { var weatherDto = JsonConvert.DeserializeObject<WeatherDto>(json); if (weatherDto == null) return null; var weatherConditions = new WeatherConditions() { Title = weatherDto.currently.summary, Description = weatherDto.currently.summary, TemperatureC = (int)Math.Ceiling(TemperatureConverter.FahrenheitToCelsius(weatherDto.currently.temperature)), TemperatureF = (int)Math.Ceiling(weatherDto.currently.temperature), Icon = Icons.GetCssClass(weatherDto.currently.icon), Location = location.City, CountryCode = location.CountryCode, UsesFahrenheit = location.UsesFahrenheit, Service = "Forecast.io", ServiceUrl = "http://forecast.io/" }; return weatherConditions; }
protected void Convert_Click(object sender, EventArgs e) { if (IsValid) // om validatorerna går igenom så körs allt detta! { int startTemp = int.Parse(EnterTempStart.Text); // tar in värderna som personen har skrivit in och skapar nya variablar för dom! int endTemp = int.Parse(EnterTempEnd.Text); // samma här! int jumpTemp = int.Parse(EnterTempJump.Text); // samma här! if (EntryC.Checked == true) { for (int i = startTemp; i <= endTemp; i += jumpTemp) { int CelsiustoF = TemperatureConverter.CelsiusToFahrenheit(startTemp); TableRow topRow = new TableRow(); // dessa finns redan som val dessa tableHeaderRows och celler! TableCell leftCell = new TableCell(); TableCell rightCell = new TableCell(); Presentation.Rows.Add(topRow); topRow.Cells.Add(leftCell); topRow.Cells.Add(rightCell); leftCell.Text = startTemp.ToString(); rightCell.Text = CelsiustoF.ToString(); startTemp += jumpTemp; // kanske ska vara någon annanstanns } } else if (EntryF.Checked == true) { for (int i = startTemp; i <= endTemp; i += jumpTemp) { TableRow topRow = new TableRow(); // dessa finns redan som val dessa tableHeaderRows och celler! TableCell leftCell = new TableCell(); // skapar celler!! TableCell rightCell = new TableCell(); int FahrentoC = TemperatureConverter.FahrenheitToCelsius(startTemp); // tar in uträckningsmetoden från klassen! Presentation.Rows.Add(topRow); // lägger till alla rader topRow.Cells.Add(leftCell); // och alla celler! topRow.Cells.Add(rightCell); leftCell.Text = startTemp.ToString(); // sätter cellen till vänster till det man skriver in som start! rightCell.Text = FahrentoC.ToString(); // sätter in den nya uträckningen i cellen till höger! startTemp += jumpTemp; // kanske ska vara någon annanstanns } } TableRow headeRow = new TableRow(); // skapar rader! TableHeaderCell headerCell1 = new TableHeaderCell(); // skapar celler! TableHeaderCell headerCell2 = new TableHeaderCell(); headeRow.Cells.Add(headerCell1);// skapar de två översta cellerna! headeRow.Cells.Add(headerCell2); Presentation.Rows.AddAt(0, headeRow);// Lägger in C och F överst på tabellen! if (EntryC.Checked) { headerCell1.Text = "C"; headerCell2.Text = "F"; EntryF.GroupName = "changed"; } else { EntryC.GroupName = "changed"; // gör det möjligt att byta mellan knapparna fick hjälp med denna! headerCell1.Text = "F"; headerCell2.Text = "C"; } Presentation.Visible = true; } }
public void FahrenheitToCelsiusTests(double f, double expected) { double c = TemperatureConverter.FahrenheitToCelsius(f); Assert.That(c, Is.EqualTo(expected)); }