Професионална програма
Loading...
+ Нов въпрос
Axiomatik avatar Axiomatik 100 Точки
Best Answer

Two problems:

Line 20 : In output-message use remaining energy and not 0 for the final message.

Line 27-30 : Energy needs to be increased with the current round-counter, which is 3 at the first time, 6 the second time …

Best,

Refactored code (100%) :

using System;

namespace Counter_Strike
{
    class Program
    {
        static void Main(string[] args)
        {
            int energy = int.Parse(Console.ReadLine());
            string input = string.Empty;

            int rountCounter = 0;

            while ((input = Console.ReadLine()) != "End of battle")
            {
                int distance = int.Parse(input);

                if (energy < distance)
                {
                    Console.WriteLine($"Not enough energy! Game ends with {rountCounter} won battles and {energy} energy");
                    return;
                }

                rountCounter++;
                energy -= distance;

                if (rountCounter % 3 == 0)
                {
                    energy += rountCounter;
                }
            }

            Console.WriteLine($"Won battles: {rountCounter}. Energy left: {energy}");
        }
    }
}

0
zakaza avatar zakaza 0 Точки

Thank you!

0