C# 需要一个文本框来显示C中的循环#
目前的任务是“使用适当的循环类型,以1.5的步骤将温度变量(需要是浮点型)的值从5变为23。” 但我无法使用他们想要的1.5进行计算,因为1.5不属于浮点格式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 = "";
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();
}