struggling with this task. What’s wrong with my code? Thank you in advance
Console.Clear();
int number1 = int.Parse(Console.ReadLine());
int number2 = int.Parse(Console.ReadLine());
int number3 = int.Parse(Console.ReadLine());
max = 0;
if (number1 > number2)
{
max = number1;
}
if (number1 < number2)
{
max = number2;
}
if (max > number3)
{
Console.WriteLine(max);
}
else
{
Console.Write(number2);
}
‘Just cannot understand what is wrong. Code is not working’
>Solution :
There are two problems with your code.
you need to have number3 in your last else.
else
{
Console.Write(number3);
}
and also you need to declare max as int.
you also have to ensure the input value is convertible to int in your code.
and it would be best if you also handled the corner cases like when two or three numbers are equal.