mercredi 22 février 2017

Why is my if statements not being recognized..C# [duplicate]

This question already has an answer here:

I am trying to create a game for an assignment and I can't figure out why I am getting an error saying "Use of unassigned local variable 'result'".. I had it equal to false in my declaration at first but it still did not return anything. It's return determines if the user has lost or won.

public bool DeterminWin()
    {
        bool result;

        if (southbank.Contains("Chicken") && southbank.Contains("Fox") && southbank.Contains("Grain"))
        {

            result = true;
        }

        if (northbank.Contains("Chicken") && northbank.Contains("Grain"))//lose if chicken and grain are together on north bank
        { result = false; }



        if (northbank.Contains("Fox") && northbank.Contains("Chicken"))// lose if fox and chicken are together on north bank
        { result = false; }



        if (southbank.Contains("Fox") && southbank.Contains("Chicken"))// lose if fox and chicken are together on south bank
        { result = false; }



        if (southbank.Contains("Chicken") && southbank.Contains("Grain"))//lose if chicken and grain are together on south bank
        { result = false; }

        return result;
    }

Aucun commentaire:

Enregistrer un commentaire