Please help me with the task: Track the delivery drones

Hello, I’m working on this task:

At our resistance base, we have delivery drones. These are very simple flying robots that know only how to deliver boxes to the destination point. After some time, the drones begin to break. They’ll move forward and then backward. We still keep a drone in circulation as long as it moves forward more often than backward. The drones log all their actions the console until it reaches the destination.
Your program should print the distance from the starting point to the destination. If, at some point, the drone performs more steps backward than forward, the program should terminate the delivery and output “Go back to base. Delivery failed.” to the console.
You can assume that the drone flies along a straight line with no turns. If the drone outputs “forward”, it means that it has moved 10 meters forward. Otherwise, if it moved backward, the output will be “backward”. When the drone reaches the destination point, it prints “Destination reached.” to the console In this case, the program should output the distance from the starting point to the destination. Use a switch to check the input from the drone.
Example 1:
>forward
>forward
>backward
>forward
>forward
>Destination reached.
30
Example 2:
>forward
>backward
>backward
Go back to base. Delivery failed.

Here is my code:


namespace SwitchStatement
{
   class DeliveryDrones
   {
       static void Main()
       {          

           bool isDestinationReached = false;
           bool goBackToBase = false;
           string move;
           int distance = 0;

           while (!isDestinationReached && !goBackToBase)
           {
               move = Console.ReadLine();

               switch (move)
               {

                   case "forward":
                       distance = distance + 10;
                       break;
                   case "backward":
                       if (distance >= 0)
                       {
                           distance = distance - 10;
                       }
                       if (distance < 0)
                       {
                           goBackToBase = true;
                           Console.WriteLine("Go back to base. Delivery failed.");
                       }
                       break;
                   case "Destination reached.":
                       Console.WriteLine(distance);
                       break;
               }

           }
       }
   }
}

The debugger and CodeEasy output don’t show any errors, the program calculates the distance for two given examples correctly, but the system says “Your solution did not pass all our tests”. 2 questions:

  1. Where is my mistake? :grinning:
  2. How to search for an error in similar cases if you have no clue what and where to search for?
    Thanks

UPD:
Considering the 2nd question…
The same situation is with the next exercise about drones. The code has no errors and calculates the coordinates correctly in Visual Studio, but can’t pass some unknown tests :sos: :sob::

same as in while in one of the previous solutions. StackOverFlowException and that’s why tests are failing without any output.
You forgot to set:
isDestinationReached = true;

1 Like

Right! Thank you so much, Lena! Sorry to bother you with similar questions. Maybe I will learn it after all :slight_smile: