我在显示文本框中计算的平均值和数字时出现问题..当我点击显示按钮时它只返回0 0值,我认为问题出在我的字符串阅读器中,但我不知道我在哪里出错了我的代码
//initialising the array
int numbers = counts;
Array.Resize(ref scoreArray, numbers);
//outputting and displaying the count in a text box
for (int count = 1; count > numbers; count++)
{
scoreArray[count] = scores;
txtCount.Text = count.ToString();
}
}
//catch statement for displaying error message
catch (Exception)
{
MessageBox.Show(" Please enter valid number ");
}
}
private void btnDisplay_Click(object sender, EventArgs e)
{
string toDisplay = string.Join(Environment.NewLine, scoreArray);
MessageBox.Show(toDisplay);
txtNumScores.Focus();
txtCount.Clear();
txtAverage.Clear();
txtNumScores.Clear();
txtTotal.Clear();
counts = 0;
total = 0;
}
private void btnClear_Click(object sender, EventArgs e)
答案 0 :(得分:0)
更改
for (int count = 1; count > numbers; count++)
{
scoreArray[count] = scores;
txtCount.Text = count.ToString();
}
到
for (int count = 1; count < numbers; count++)
{
scoreArray[count] = scores;
txtCount.Text = count.ToString();
}
答案 1 :(得分:0)
似乎你的整个for循环取决于int numbers = count;
的初始值以及之后
btnDisplay_Click中的count = 0;
所以number = 0;
因此你的for循环似乎根本没有执行,所以,你应该交叉验证上面@Jorge指出的for循环条件。