我对编码非常不好,而且我不懂循环。有人可以帮助我缩短我的代码吗?
if (correct > 0 && correct < 5) {
score = 3;
}
if (correct > 4 && correct < 7) {
score = 2;
}
if (correct > 6 && correct < 9) {
score = 1;
}
if (correct > 8 && correct < 11) {
score = 0;
}
答案 0 :(得分:0)
您没有指定语言,因此,假设您有两个int数组,如下所示:
int start[4] = {0, 4, 6, 8};
int end[4] = {5, 7, 9, 11};
You can do something like this:
int score = -1;
int i = 0;
while (index > 0) {
if ((correct > start[i]) && (correct < end[i])) score = 3 - i++;
}