#Anyone who can tell me why this doesnt work? im trying to learn how to code <3

1 messages · Page 1 of 1 (latest)

wise turtle
#

at the bottom "teamOneWin" is marked with red

#

and is an error

#

but i dont get why

#

sry if its a stupid question

#
   bool gameover = false;
        while (gameover != true)
        {

            Console.WriteLine("Which team won, Team One or Team Two? or do you want to randomise it?, if you do type random");
            string winner = Console.ReadLine();

            if (winner == "random" || winner == "Random")
            {
                Console.Clear();
                teamOneWin = randomWin();
                gameover = true;
            }

            if (winner == "One" || winner == "one")
            {

                Console.Clear();
                teamOneWin = true;
                teamTwoWin = false;
                gameover = true;
            }
            else if (winner == "two" || winner == "Two")
            {
                Console.Clear();
                teamOneWin = false;
                teamTwoWin = true;
                gameover = true;
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Not a valid answer" + "\n");
            }
        }
        
        if (teamOneWin == true)
        {

        }
        break;
oblique osprey
#

When you get an error and want to ask for help, you should include that error in your question. That way others don't have to guess what is wrong.
This is especially true, if you don't show your entire code but only a snippet; To exemplify: teamOneWin is not declared in the code you show. But if that was the issue, the error would be occurring further up.

wise turtle
#

dk if this is what u mean

#

and this si the entire code

#

supposed to randomise champions from league of legends

#

im not close to being done yet

#

so i have a lot of unused variables

oblique osprey
#

Okay. Your issue is, that you declare teamOneWin as a local variable (as opposed to a field or property), and don't give it a value before trying to access it.

#

Generally I would recommend that you stick to the "traditional" way of writing code in C#, where you actually declare a class and methods around executable code, instead of letting the framework take care of that. That would not only teach you more about how the code is (supposed to be) structured, but it will also make it more readable.

#

Not to mention that you will be needing class declarations eventually anyway.

wise turtle
#

Thank you!