0

Getting a lot of errors when using ENUM types with SWITCH statements.

public skin Diff { Easy, Medium, Hard } int health=0; Diff pick =Console.Deadline(); switch(pick) case Diff.Easy: easy(); health=3; break; case Diff.Medium: medium(); health =2; break; case Diff.Hard: hard(); health=1; break; default: easy(); health=3; break; The error codes are " invalid token ';' '=' in class, struct or interface declaration " " ')' expected '{' expected " and are mostly within switch statement. Do you see the problem, how would you do it?

7th Nov 2017, 12:38 AM
Humble
Humble - avatar
3 odpowiedzi
+ 1
//this way it would work using System; public enum Diff : int {Easy, Medium, Hard}; public class Program { public static void easy(){} public static void medium(){} public static void hard(){} public static void Main() { int health=0; Diff pick=(Diff) Int32.Parse(Console.ReadLine()); switch(pick) {case Diff.Easy: easy(); health=3; break; case Diff.Medium: medium(); health =2; break; case Diff.Hard: hard(); health=1; break; default: easy(); health=3; break; } } }
7th Nov 2017, 1:32 AM
Petr Hatina
Petr Hatina - avatar
0
Thanks I've learnt a lot
7th Nov 2017, 6:36 AM
Humble
Humble - avatar
0
In summary the enumeration structure was intended for Programmer's convenience not user's. And it is more efficient to use strings to request text input. :)
7th Nov 2017, 6:38 AM
Humble
Humble - avatar