【发布时间】:2014-06-02 15:37:36
【问题描述】:
int none[5];
int ntwo[5];
(the following is in a switch statement);
if (answer == userAnswer)
{
printf("Correct!\n");
score = prevScore + 1;
prevScore = score;
}
else
{
printf("Incorrect. The correct answer was %d\n\n", answer);
none[i] = number1;
ntwo[i] = number2;
}
}
break;
(Switch 语句结束)
它给了我一个错误,说“变量警告“无”设置但未使用”。我已经清楚地使用了它。我不知道为什么会发生这个错误。仅供参考,您看到的所有其他变量都已被声明。我刚刚取出了出现数组的 imp 部分。
【问题讨论】:
-
您是否在某处使用了该值?
-
警告正是它所说的,你设置了
none,但从不使用它的值。你所做的就像说int myNum = 0;然后在其他任何地方都不使用myNum。 -
但是我用过。 "无[i] = number1;ntwo[i] = number2;"
-
那里看不到,但它处于循环中,将运行 5 次。 i 值将从 1 变为 5。