Hello, I’m working on this task:
Write a program that reads three numbers from the console and then outputs the middle value of the three numbers. For example:
>54
>4456
>2
54
Here is my code:
namespace ConsoleInput
{
public class TheMiddle
{
public static void Main(string[] args)
{
string aString = Console.ReadLine();
string bString = Console.ReadLine();
string cString = Console.ReadLine();
int a = int.Parse(aString);
int b = int.Parse(bString);
int c = int.Parse(cString);
if ((a > b) && (b > c))
{
Console.WriteLine(b);
}
else if((a > c) && (c > b))
{
Console.WriteLine(c);
}
else
{
Console.WriteLine(b);
}
// Perform checks here to find out which number is the middle one.
}
}
}
Can anyone please help me to solve it? Why is it not right?