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?
3 Answers
+ 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;
}
}
}
0
Thanks I've learnt a lot
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. :)