Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 需要一个文本框来显示C中的循环#_C# - Fatal编程技术网

C# 需要一个文本框来显示C中的循环#

C# 需要一个文本框来显示C中的循环#,c#,C#,目前的任务是“使用适当的循环类型,以1.5的步骤将温度变量(需要是浮点型)的值从5变为23。” 但我无法使用他们想要的1.5进行计算,因为1.5不属于浮点格式 private String calc(float length, float width, float depth, float surfaceArea, float volume) { float tempCount = 5; string output = "";

目前的任务是“使用适当的循环类型,以1.5的步骤将温度变量(需要是浮点型)的值从5变为23。”

但我无法使用他们想要的1.5进行计算,因为1.5不属于浮点格式

private String calc(float length, float width, float depth, float surfaceArea, float volume)
        {
            float tempCount = 5;
            string output = "";
            float heatingCost;
            while (tempCount <= 23)
            {
                tempCount += 1.5;
                heatingCost = (25 - tempCount) * float.Parse(txtVolume.Text)/32500;
                output += "$" + heatingCost + "\r\n";

            }
            return output;
        }
专用字符串计算(浮动长度、浮动宽度、浮动深度、浮动表面面积、浮动体积)
{
浮点数=5;
字符串输出=”;
浮动加热成本;

而(据我所知,tempCount=2&&validWidth=5&&validLength=2&&validDepth

到的值在步数为1.5时为5到23

是对for循环的完美描述:

  for (double temperature = 5.0; temperature <= 23; temperature += 1.5) {
    ...
  }

for(double temperature=5.0;temperature什么意思1.5不属于float格式?如果您查看编译器告诉您的错误,很明显float可以声明为
float myFloat=1.5f;
  for (double temperature = 5.0; temperature <= 23; temperature += 1.5) {
    ...
  }
  // You don´t want any input arguments
  private String Prices() {
    double value = double.Parse(txtVolume.Text); 

    // when collecting string from its parts, use StringBuilder
    StringBuilder sb = new StringBuilder();

    for (double temperature = 5.0; temperature <= 23; temperature += 1.5) {
      double cost = (25.0 - temperature) * volume / 32500.0;

      if (sb.Length > 0)
        sb.AppendLine();

      sb.Append(String.Format("${0}", cost)); 
    }

    return sb.ToString();
  }