Thank you Jon,
Ok, so you have level
declared at the top of your script as a string
. The following line;
level = int.Parse(input);
…tries to parse the value of input
and where possible, returns an int
. So here is the issue, you are trying to put a type of int
into a variable of type of string
.
You have some choices. You could keep level
as a string
and change that line to this;
level = int.Parse(input).ToString();
The error will go away, however you may then want to address the switch
statement and consider putting quotation marks around each of the cases, e.g. “1”, “2” and so on. Sometimes you can get away without any specific casting with ints
and strings
, but not always.
An alternative would be to set level
to be an int
in your declaration at the top, you can then leave the switch
statement as-is and there will be no need for the .ToString()
.
Probably best to go back a bit in this lecture and see what level
is supposed to be declared as.
Hope this helps