잘 작동하는 코드를 작성했습니다. 그러나 나를 짜증나게하는 것이있다. 다음은 코드입니다.
string secretWord = "ola";
string guess;
int counter = 4;
Console.WriteLine("Try to guess a secret word that contain 3 character. You have 4 attemps");
for (int i = 0; i<3; i++)
{
guess = Console.ReadLine();
if (guess == secretWord)
{
Console.WriteLine("Well done! You guessed correctly");
break;
}
else if (guess.Length != 3)
{
counter--;
Console.WriteLine("Only three characters. You lost one attempt");
Console.WriteLine("You have now {0} attempts", counter);
}
else if (guess != secretWord)
{
counter--;
Console.WriteLine("Wrong. you have now {0} attempts", counter);
}
if(counter == 0)
{
Console.WriteLine("Bad lucky. The secret word is {0}", secretWord);
}
}
나를 괴롭히는 것은 사용자가 4 번 잘못한 경우입니다. 마지막 하나가 표시된 후
"틀 렸습니다. 이제 0 번 시도했습니다."
"나쁜 행운아. 비밀 단어는 올라"
이 줄을 제거 할 수있는 방법이 몇 가지 있습니다. "잘못되었습니다. 이제 시도 횟수가 0입니다"??
else if
이런 식으로 마지막 을 변경할 수 있습니다
else if (guess != secretWord)
{
counter--;
if(counter == 0)
{
Console.WriteLine("Bad lucky. The secret word is {0}", secretWord);
break;
}
Console.WriteLine("Wrong. you have now {0} attempts", counter);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다