Please help me with the task: "Minimum finder"

Hello, I’m working on this task:

Write a program that reads two numbers from the console and then outputs the lesser of the two numbers. Use a short (one line) version to read a string from the console and convert it to int .
For example:
>123
>97
97

Here is my code:


namespace ConsoleInput
{
   public class TheMinimum
   {
       public static void Main(string[] args)
       {
           int a = int.Parse(Console.ReadLine());// Read a line and convert it to int (short version)
           int b = int.Parse(Console.ReadLine());// Read a line and convert it to int (short version)

           if (a > b)
           {
               Console.WriteLine({b});
           }
           else (a < b)
           {
               Console.WriteLine({a});
           }
       }
   }
}


Can anyone please help me to solve it?

There are several problems here. First one - the way you output the number. There is no need for the curly braces:
Console.WriteLine(a);
The second one, is how you write else. You shouldn’t put the condition after else, so it should be:

if (condition)
{
    ...
}
else
{
    ...
}

If you want a separate condition for the else clause (which you don’t need in this task) you can do this with an additional if:

if (condition1)
{
    ...
}
else if (condition2)
{
    ...
}

Thanks so much! :wink:

1 Like