【发布时间】:2018-05-22 05:01:34
【问题描述】:
我正在解决 Codeeasy.net 上的一个问题,但我终其一生都无法弄清楚。如果有人可以帮助我。这是它应该做的。
class AntivirusScan
{
static void Main(string[] args)
{
int fileIndex = 0;
bool hideMode = false;
bool heDoesntKnow = true;
while (heDoesntKnow)
{
string answer = Console.ReadLine();
if (answer == "scan")
{
fileIndex = fileIndex + 1;
Console.WriteLine($"scanning file {fileIndex}");
}
if (hideMode == true)
Console.WriteLine($"can't scan files for viruses");
if (answer == "hide")
{
Console.WriteLine($"can't scan files for viruses");
hideMode = true;
}
if (answer == "unhide")
{
fileIndex=fileIndex+1;
Console.WriteLine($"scanning file {fileIndex}");
hideMode=false;
}
if (answer == "game over")
{
Console.WriteLine($"run");
heDoesntKnow = false;
}
}
}
}
这是我的代码。如果它被隐藏,它应该返回它无法扫描。相反,它只是通过它供电。它出现一次,然后继续不做它应该做的事情。
它应该从提示中读取
scan
scan
hide
scan
scan
unhide
scan
game over
这是它的输出
scanning file 1
scanning file 2
can't scan files for viruses
scanning file 3
can't scan files for viruses
scanning file 4
can't scan files for viruses
can't scan files for viruses
scanning file 5
scanning file 6
run
这是它应该输出的内容
scanning file 1
scanning file 2
can't scan files for viruses
can't scan files for viruses
scanning file 3
run
【问题讨论】:
-
是因为你想要
continue;,还是else if?