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();
}