Hello, I’m working on this task:
You’ve met another droid that knows a secret integer between 1 and 8. Add or remove this modifiers to enable a guessing game where the user should guess that secret number. (In this case, it is 6)
Here is my code:
namespace This
{
class AnotherDroid
{
private int secretNumber;
public AnotherDroid(int secretNumber)
{
this.secretNumber = secretNumber;
}
public void GuessSecretNumber()
{
int secretNumber = -1;
while (secretNumber != this.secretNumber)
{
Console.WriteLine("Input your guess [1..8]");
secretNumber = int.Parse(Console.ReadLine());
if (secretNumber != secretNumber)
{
Console.WriteLine("Nope. Try again!");
}
}
Console.WriteLine("You've guessed! Great work!");
}
}
class HowToUseThis
{
public static void Main()
{
var droid = new AnotherDroid(6);
droid.GuessSecretNumber();
}
}
}
Не приймає цей варіант, хоча в віжуал студіо працює. Підкажить, будь ласка, де моя помилка?
Кодізі видає:
System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Number.ParseInt32(ReadOnlySpan`1 value, NumberStyles styles, NumberFormatInfo info)
at System.Int32.Parse(String s)
at This.AnotherDroid.GuessSecretNumber()
at This.HowToUseThis.Main()