【发布时间】:2020-05-21 18:40:18
【问题描述】:
int[] subject = { 0, Maths, English, Construction, IT };
int t = 1;
int c = 0;
while (t < 4)
{
if (Convert.ToInt32(Chart[c].Text) != 0)
{
if (c < 12)
{
c++;
}
Counter();
}
else
{
int m = random.Next(1, 4);
Chart[c].Text = Convert.ToString(m);
subject[m]--; // this isnt working!!
Chart[c].Refresh();
tbTotal--;
}
}
private void Counter()
{
if(Maths == 0 && math == false)
{
math = true;
t++;
}
if (English == 0 && english == false)
{
english = true;
t++;
}
if(IT == 0 && it == false)
{
it = true;
t++;
}
if(Construction == 0 && construction == false)
{
construction = true;
t++;
}
没有减去变量“m”以允许 while 循环的转义并限制向文本框添加值。
主语使用不是记录意义,这意味着 if 语句不适用。因为主题永远不会达到 0。
这会创建一个无限的 while 循环并冻结。
【问题讨论】:
-
你在哪里增加
t因此subject[t] < 4总是true -
Counter() 有基本的 if 语句,当数组内的主题变为 0 时会切换和递增,由“subject[m]--;”控制
-
解释
subject[t]AKAsubject[1]将如何大于 4? -
while (t < 4)永远不会离开循环,因为t总是等于 1。 -
您的代码令人沮丧。
t的范围是什么?看起来它只属于带有while循环的代码,但它神奇地重新出现在Counter函数中。 “数学、英语、建筑、IT”的价值是什么?要获得好的帮助,您需要发布可以为我们复制问题的代码。
标签: c# arrays winforms while-loop