I'm pretty new to coding -- C# is the first language I've attempted to learn -- and I'm having trouble with one of my codes. I'm using Visual Studio, and the gist of this code is that I'm trying to pull numbers from three text boxes, pass them to a method that returns the largest number, and then display the result in another text box. I've trawled through other threads on this site looking for a solution, but with no luck.
Visual Studio doesn't show me any errors in my code, and the program executes fine. But when I enter the three numbers, I'm not able to get the largest to display in the answer box. I don't think it's an issue with getting the numbers from the boxes, as I can print those numbers individually if I choose to. However, I also think I've written the method correctly (think being the operative word here).
Side note: I know there's a Math.Max() method I can use instead of the if/else statements, but I'm trying to understand the basics before I start using built-in methods like that.
private double max(double firstNum, double secNum, double thirdNum)
{
double maxNum = 0;
if (firstNum > secNum && firstNum > thirdNum)
{
maxNum = firstNum;
}
else if (secNum > firstNum && secNum > thirdNum)
{
maxNum = secNum;
}
else
{
maxNum = thirdNum;
}
return maxNum;
}
private void retBtn_Click(object sender, EventArgs e)
{
double num1, num2, num3;
num1 = double.Parse(num1Box.Text);
num2 = double.Parse(num2Box.Text);
num3 = double.Parse(num3Box.Text);
double biggestNum = max(num1, num2, num3);
ansBox.Text = biggestNum.ToString();
}
Here's the code I currently have. Any help would be greatly appreciated!
EDIT: The other thread that has been linked does not answer the same question I'm asking. It shows how to write the method that finds the biggest number, which I have already done. The issue I'm having is that when I press the retBtn, nothing appears in the textbox. I think the issue is in my the "double biggestNum = max(num1, num2, num3)" or in the return statement of my method.