Reputation: 309
Whenever I declare an enum
, it simply won't compile. My code looks like this:
private enum race {HUMAN, ORC, GOBLIN, UNDEAD}
// The name of the player
string playerName;
// The Health Points of the player. Is to be modified a LOT. Keep that in mind!
int HP = 100;
// Made to test if the name chosen i the right one
bool nameIsRight = false;
cout("Hello fair traveler!\n\n");
cout("It has come to my knowledge, that you, a puny warrior, is up for the challenge, that is killing the dragon\n\n");
cout("Our records seems to be damaged. What was your name again?\n\n");
cout("Enter your name: ");
// Sets playerName equal to the line entered by the player, turned into a string to prevent errors
playerName = Console.ReadLine().ToString();
cout("\n");
do
{
string test;
cout("Are you sure that is the right name? (y/n)\n");
test = Console.ReadLine();
cout("\n");
if (test.ToLower() == "y")
{
nameIsRight = true;
}
else if (test.ToLower() == "n")
{
cout("What is your name then?\n");
playerName = Console.ReadLine();
}
cout("\n");
} while (nameIsRight == false);
cout("So, your name is " + playerName + "? That is a name i haven't heard in a long time!\n\n");
cout("Just for the record, we need your race. Hope you don't mind telling it again.\n\n");
cout("1: Human\n\n2: ");
Error 1 } expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 12 10 simpleRPGConsole
Error 2 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 25 13 simpleRPGConsole
Error 3 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 25 18 simpleRPGConsole
Error 4 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 26 13 simpleRPGConsole
Error 5 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 26 18 simpleRPGConsole
Error 6 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 28 13 simpleRPGConsole
Error 7 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 28 18 simpleRPGConsole
Error 8 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 29 13 simpleRPGConsole
Error 9 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 29 18 simpleRPGConsole
Error 10 Invalid token '=' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 24 simpleRPGConsole
Error 11 Invalid token '(' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 42 simpleRPGConsole
Error 12 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 32 45 simpleRPGConsole
Error 13 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 34 13 simpleRPGConsole
Error 14 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 34 18 simpleRPGConsole
Error 15 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 39 17 simpleRPGConsole
Error 16 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 39 22 simpleRPGConsole
Error 17 Invalid token '=' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 40 22 simpleRPGConsole
Error 18 Invalid token '(' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 40 40 simpleRPGConsole
Error 19 Method must have a return type C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 41 17 simpleRPGConsole
Error 20 Type expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 41 22 simpleRPGConsole
Error 21 Invalid token '(' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 42 33 simpleRPGConsole
Error 22 Invalid token '=' in class, struct, or interface member declaration C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 44 33 simpleRPGConsole
Error 23 A namespace cannot directly contain members such as fields or methods C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 46 17 simpleRPGConsole
Error 24 A namespace cannot directly contain members such as fields or methods C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 52 15 simpleRPGConsole
Error 25 Type or namespace definition, or end-of-file expected C:\Users\Herbstein\documents\visual studio 2013\Projects\simpleRPGConsole\simpleRPGConsole\Program.cs 57 9 simpleRPGConsole
What should i do to help this? I don't wanna make something like this without enums!
Herbstein
Upvotes: 1
Views: 585
Reputation: 137398
You're not showing the entire code, but your enum
appears to be in the middle of a function. Don't do that.
Also, your methods need to be in a class
. Check out some good examples.
Also, cout
doesn't exist in C# - that's a C++ thing, and you're not using it right in any language. C# uses Console.WriteLine
.
namespace MyApp
{
// Every method (function) must be in a class
class MyProgram
{
// This is where code execution begins
static void Main()
{
Console.WriteLine("Hello, world!");
string playerName = GetPlayerName();
}
static string GetPlayerName()
{
Console.WriteLine("Some cliche narrative here. Name?");
return Console.ReadLine();
}
// We can also make nested class/struct/enum definitions that are
// "private" to the containing class.
private enum APrivateEnum { Foo, Bar }
}
enum Race { Human, Orc, Goblin, Undead }
}
Upvotes: 6