I'm having trouble with this bit of code that I'm working on. I get an error code in my parseit()method that says, "not all code paths return a value". Ideally I'm trying to call my method and parse my variables from my textbox to return true when they're valid, then I'm going to use my boolean CheckNums in the if statement shown at the bottom.

I've been trying every which way to change my code, but I get an error no matter what I do. I think I've provided the relevant code. I know others have asked this question, but no matter what I do I can't get it to work.

decimal ascore = 0;
decimal midScore = 0; 
decimal finalscore = 0; 
bool CheckNums;

parseit(out ascore, out midScore, out finalscore);

        private bool parseit(out decimal ascore, out decimal midScore, out decimal finalscore)
        {
            if (decimal.TryParse(assignmentBox.Text, out ascore) && (ascore <= 100) && (ascore >= 0))
            {
                if (decimal.TryParse(midtermBox.Text, out midScore) && (midScore <= 100) && (midScore >= 0))
                {
                    if (decimal.TryParse(finalBox.Text, out finalscore) && (finalscore < 100) && (finalscore >= 0))
                    {
                        CheckNums = true;
                        return true;
                    }
                    else
                    {
                        CheckNums = false;

                    }
                }
                else
                {
                    CheckNums = false;
                }
            }
            else
            {
                CheckNums = false;
            }
        }

if (CheckNums == true)
    {
    Switch();
    }
else
    {
    BadInput();
    }       

I see the return statement on line 16, but nowhere else. What happens if the test on line 10 fails -- what will the function return??

line 6 you should poot

bool

as well

No, he already defined it as bool on line 4. I agree with Ancient dragon, he should probably use if else if and put return for each of that if statement.

commented: my mistake, i tought it was the method itself rather then method call +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.