Please help me with the task: Antivirus scan

Hello, I’m working on this task:

Task with high complexity! It is ok to skip :wink:
You need to write a program that sends files to the antivirus scan. It should scan files only when Ritchie is NOT watching Noname’s state. The program should understand 4 commands: “scan”, “hide”, “unhide”, and “game over”. It should have two modes that can be toggled by using the commands “hide” and “unhide” commands. The default mode is “unhide”, which means that Ritchie is not watching. If the input is “scan” during the mode “unhide”, the program should output “scanning file {number}” where number is an integer that starts from 1 and increments by 1 for every new file. If the user inputs “scan” during the “hide” mode, the program should output “can’t scan files for viruses”. As soon as Ritchie leaves, the input will be switched to “unhide” and then it should be able to scan again. Your program should listen to the input commands indefinitely until the input is “game over”. In this case, the program should output “run” and exit. For example:
>scan
scanning file 1
>scan
scanning file 2
>hide
>scan
can’t scan files for viruses
>scan
can’t scan files for viruses
>unhide
>scan
scanning file 3
>game over
run

Here is my code:


namespace WhileLoop
{
   class AntivirusScan
   {
       static void Main(string[] args)
       {

           bool ritchieIsNotWatching = true;
           bool canScan = true;
           int number = 0;

           while (canScan)

           {
               string command = Console.ReadLine();

               if (command == "scan")
               {

                   if (ritchieIsNotWatching == true)

                   {
                       number++;
                       Console.WriteLine($"scanning file {number}");
                   }

                   if (ritchieIsNotWatching == false)
                   {
                       Console.WriteLine("can't scan files for viruses");

                   }

               }

               if (command == "hide")
               {
                   ritchieIsNotWatching = false;
                   Console.WriteLine("can't scan files for viruses");
               }

               if (command == "unhide")

               {     
                ritchieIsNotWatching = true;
               }

               if (command == "game over")
               {
                   canScan = false;
                   ritchieIsNotWatching = false;
                   Console.WriteLine("run");
               }




           }

       }
   }
}


Can anyone please help me to solve it?

1 Like

Читаємо умову задачі:

If the user inputs “scan” during the “hide” mode, the program should output “can’t scan files for viruses”.

В яких ще умовах фраза “can’t scan files for viruses” може бути виведена на екран в умовах задачі?
А в яких умовах вона виводиться в вашому рішенні?)

Дякую! :star_struck: Побачила, працює! :heart_eyes:

1 Like