[英]temperature conversion using functions c#
你好,我環顧四周,找不到使用函數來轉換溫度的 ac# 控制台應用程序。 我幾乎完成了該程序,但由於某種原因,如果有人可以幫助我找到很棒的答案,則攝氏溫度不會顯示出來!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace temp_conversion
{
class tempConversion
{
static void Main(string[] args)
{
double far, cel;
far = GetTemp("Far");
cel= Celcius(far);
DisplayResults(far,cel);
}//end of main method
public static double GetTemp(string temp)
{
string inputValue;
double far;
Console.WriteLine("Enter Fahrenheith Temp");
inputValue = Console.ReadLine();
far = double.Parse(inputValue);
return far;
}
static double Celcius(double far)
{
double cel = 5.0 / 9.0 * (far - 32);
return cel;
}
public static void DisplayResults (double far , double cel)
{
Console.WriteLine("Fahrenhieith temp {0:N2}", far);
Console.WriteLine("C ", cel);
Console.ReadLine();
return;
}
}//end of class
}
您需要像在 cel 的寫行中一樣包含 {0:N2}。
例如
Console.WriteLine("Celcius Temp {0:N2}", cel);
你應該更換
Console.WriteLine("C ", cel);
和
Console.WriteLine("C {0:N2} ", cel);
你也可以試試這個
Console.WriteLine("C {0:0.00}", cel);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.