繁体   English   中英

使用函数 c# 进行温度转换

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM