1

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();
    }       
4
Contributors
3
Replies
22
Views
3 Years
Discussion Span
Last Post by Michael27
1

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??

1

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.

Votes + Comments
my mistake, i tought it was the method itself rather then method call
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.