作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我仍在学习 C# 的基础知识,目前正忙于编写一些让我陷入无限循环的代码。
do
{
Console.Write("Please enter the Exam mark for student " + (index + 1) + ": ");
Exam[index] = double.Parse(Console.ReadLine());
Console.Write("Please enter the DP for student " + (index + 1) + ": ");
DP[index] = double.Parse(Console.ReadLine());
Final[index] = (DP[index] + Exam[index]) / 2;
index++;
} while (DP[index] != 999);
当我输入 999 时,密码没有中断。
最佳答案
在检查 while
条件之前,您将索引增加 1。我猜该索引的值是 0
...
一个解决方案可以是记住变量中的前一个值,或者从索引中减去一个:
} while (DP[index - 1] != 999);
另一个问题可能是 double 的使用,因为它不精确,如果您输入该值,它并不总是与 999
匹配。如果可以,请使用 int
或 decimal
。
关于C# While 无限循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36979267/
我是一名优秀的程序员,十分优秀!