Please help me with the task: Methods.FunctionalModule

Привіт! Допоможіть, будь ласка, розібратись, чому Codeasy не приймає рішення, яке працює ніби коректно у Visual Studio?

task:

Task with high complexity! It is ok to skip :wink:
Noname’s functional module consists of 4 functions: FromAToF, FromGToL, FromMToR, and FromSToZ, but Noname doesn’t know when to call which one. You need to write a program - think of it as a dispatcher - that routes an entered command to the correct function. You should read input commands from the console and if the command begins with a letter in the English alphabet that is located between “a” and “f”, such as “fix” or “Comment,” you should call function FromAToF with the command as a parameter. If the first letter of the command is between “g” and “l”, you should call FromGToL, again with the command as a parameter. Similarly, if the first letter is between “m” and “r”, call FromMToR with the command as a parameter, and in all other cases, call FromSToZ with the command as a parameter. For this program, commands are guaranteed to start with a letter. But pay attention: it can be either an uppercase or lowercase letter; for example, “fix” or “Fix”. Your program should therefore be case-insensitive. The program should listen to the input commands, and when one is given, run the method corresponding to that command. When the user types “exit”, the program should exit. For example:
>collapse
FromAToF executes collapse.
>Globalize
FromGToL executes Globalize.
>optimize
FromMToR executes optimize.
>Wrap
FromSToZ executes Wrap.
>exit

Here is my code:


namespace Methods
{
   class FunctionalModule
   {
       static void Main(string[] args)
       {

           bool printCommands = true;

           while (printCommands)

           {
               string command = Console.ReadLine();

         

               string commandLower = command.ToLower();
               char firstChar = commandLower[0];


               if ((firstChar >= 'a') && (firstChar <= 'f') && (command != "exit"))

               {
                   FromAToF(command);
               }

               if ((firstChar >= 'g') && (firstChar <= 'l'))

               {
                   FromGToL(command);
               }

               if ((firstChar >= 't') && (firstChar <= 'r'))

               {
                   FromMToR(command);
               }

               if ((firstChar >= 's') && (firstChar <= 'z'))

               {
                   FromSToZ(command);
               }

               if (command == "exit")

               {
                   printCommands = false;
               }

               
           }


           static void FromAToF(string command)
               {
                   Console.WriteLine($"FromAToF executes {command}.");
               }

               static void FromGToL(string command)
               {
                   Console.WriteLine($"FromGToL executes {command}.");
               }

               static void FromMToR(string command)
               {
                   Console.WriteLine($"FromMToR executes {command}.");
               }

               static void FromSToZ(string command)
               {
                   Console.WriteLine($"FromSToZ executes {command}.");
               }

       }

           
   }
}

Double check this part. Especially the first part of if :slight_smile:

  1. You’ve accidentally put all static methods inside of Main. They should start after the end of Main method.
2 Likes

oh) really, first I had to learn the alphabet :smile:

it seems to be my favorite sport to put methods in the main method

Thanks a lot, Lena! :yellow_heart: :blue_heart: