Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using System;

public class Source
{
    static public void Main ()
    {
        int mob;
		int character = 15;
		Random random = new Random();
		int i;
		string[] mobs = {"hobgoblin", "goblin", "imp"};
		for(i = 0;i < 1; i++);
		Console.WriteLine("you are a adveturer");
		Console.WriteLine("and you are equiped with a sword and a bow");
		Console.WriteLine("you are walking down a path an sudenly you encounter an enemy");
		Console.WriteLine("you encountered a");
		string enemy = (mobs[(random.Next(0, 3))]);
		Console.WriteLine(enemy);
		int hitpoints;
		{
		if (enemy == "hobgoblin")
		hitpoints = 15;
		else if (enemy == "goblin")
		hitpoints = 12;
		else if (enemy == "imp")
		hitpoints = 14;
		}
		{
		string fight = Console.ReadLine();
		if (fight = attack)
		hitpoints -- 4;
		}
	
		
		
		
		
	
   }
}


What I have tried:

I have tried adding more ; but it just caused more errors
Posted
Updated 2-Jun-20 19:21pm

Quote:
I am getting C# error 1002 in my code.

First reaction, ask Google.
The error code comes with position in source code, when you ask for help, it is a nice idea to give complete information as not every one have the language ready to run with your details.

This loop is absurd:
C#
for(i = 0;i < 1; i++);

The loop is empty and can be replaced by
C#
i = 1;


Advice: Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
C#
using System;

public class Source
{
    static public void Main ()
    {
        int mob;
        int character = 15;
        Random random = new Random();
        int i;
        string[] mobs = {"hobgoblin", "goblin", "imp"};
        for(i = 0;i < 1; i++);
        Console.WriteLine("you are a adveturer");
        Console.WriteLine("and you are equiped with a sword and a bow");
        Console.WriteLine("you are walking down a path an sudenly you encounter an enemy");
        Console.WriteLine("you encountered a");
        string enemy = (mobs[(random.Next(0, 3))]);
        Console.WriteLine(enemy);
        int hitpoints;
        {
            if (enemy == "hobgoblin")
                hitpoints = 15;
            else if (enemy == "goblin")
                hitpoints = 12;
            else if (enemy == "imp")
                hitpoints = 14;
        }
        {
            string fight = Console.ReadLine();
            if (fight = attack)
                hitpoints -- 4;
        }
    }
}

Indentation style - Wikipedia[^]

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
[Update]
By the way, where have you found this syntax:
C#
hitpoints -- 4;
 
Share this answer
 
v2
No offense, but I think you should take it a bit slower.

I am not going to solve things for you, only pointing out what I see on the fly (and I might oversee something).

- You are not seeding the random. In c# the constructor makes it for you, but if you want to reduce the "repetitions" of the pseudo-random series you might want to give it something else.
- EDIT ADD: The for limits are wrong, you are not going to do a loop, only a single execution
- The for has no brackets, so it will affect only the very next line.
- You open brackets after int hitpoints but there is nothing matching in that position. I suppose that are the opening brackets of the for and you just added the other things (the console write and read) in the wrong position.
- After the "You encountered a ..." you don't ask the user to take any action or what the options are, but you expect a concrete thing afterwards.
- You are not comparing fight to something, you are assigning it.
- EDIT ADD:The brackets of the fight part are wrong.
- The usage of -- by "hitpoints" is wrong.

- EDIT ADD:The scope / context of the for makes not really sense over there. If what you want is to fight until killed or dead, then you should use another loop construct taking the hitpoints of both parts fighting in consideration as limits.

The compiler is probably giving you a list of errors, there are errors that will pop up first when you solve other issues. So just get the first error, try to find information about it, solve it and then go to the next one. Rome wasn't build in one day, don't try to solve everything at once because you will loose the perspective. One error, then the next one.

Additionally, I would strongly recommend you to start playing with the debugger. Once you manage to compile it correctly. Set a breakpoint at the beginning of your program and go line by line looking at the values of the variables.
The debugger is one of the most powerful and helpful tools you can use to find errors / causes for an error on your own. The sooner you learn how to use it, the better.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900