简体   繁体   English

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

[英]temperature conversion using functions c#

hello i have looked around and couldnt find ac# console application that uses functions to convert a temperature.你好,我环顾四周,找不到使用函数来转换温度的 ac# 控制台应用程序。 i have almost completed the program but for some reason the celcius temperature does not show up if someone could help lead me to the answer that would be great!我几乎完成了该程序,但由于某种原因,如果有人可以帮助我找到很棒的答案,则摄氏温度不会显示出来!

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
}

You need to include the {0:N2} like you have for far in the writeline for cel.您需要像在 cel 的写行中一样包含 {0:N2}。

eg例如

Console.WriteLine("Celcius Temp {0:N2}", cel);

You should replace你应该更换

Console.WriteLine("C    ", cel);

with

Console.WriteLine("C   {0:N2} ", cel);

You can also try this你也可以试试这个

Console.WriteLine("C {0:0.00}", cel); Console.WriteLine("C {0:0.00}", cel);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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