By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

Q: Phone Processes - C# Task

+8 votes

Write a program to check the current battery power level after every application and if the battery has 15% power or less (because it is an айphone), print on the console the percentage left and count of application remaining. If the battery has died display on the console the message “Phone Off”. If all applications have executed successfully and the battery has more than 15% power left, display - successful complete and percentage battery left.


  • On first line you will receive battery percentage left on start in format [number%]
  • On every next line you will receive string in format [applicationName]_[number%] till read the string “END” for stop the program. The “END” string could be “enD”, “eNd”, etc.

The input will always be valid and in the format described, there is no need to check it explicitly.


*If battery is 15% or less Connect charger -> X%” and on new line “Programs left -> N” - where “X” is percentage left and “N” is program left to execute.

*If battery is 0 or less display:  “Phone Off”.

*If execute all applications and battery have more than 15%. “Successful complete -> N%” N – is remaining power.


  • Starting percentage is an integer number in range [1..100]
  • Application name will always contains Latin letters only
  • Percentage will always be a 2 digit number in range [01..99] (always will have 2 digits! And % after that)
  • Allowed working time: 0.2 seconds. Allowed memory: 16 MB.


phone processes c# example 1

phone processes c# example 2

phone processes c# example 3

asked in C# category by user john7
edited by user golearnweb

1 Answer

+2 votes
Best answer

Here's my C# solution, mate:

using System;

namespace _04.PhoneProcess
    class PhoneProcess
        static void Main(string[] args)
            int batteryPercentage = int.Parse(Console.ReadLine().Replace("%", ""));
            int remainingApps = 0;

            while (true)
                string application = Console.ReadLine();
                if (application.ToLower() == "end") break;

                if (batteryPercentage > 15)
                    string[] appDetails = application.Split('_');
                    int currApp = int.Parse(appDetails[1].Replace("%", ""));
                    batteryPercentage -= currApp;

            if (batteryPercentage <= 0)
                Console.WriteLine("Phone Off");
            else if (batteryPercentage <= 15)

                    "Connect charger -> {0}%{2}Programs left -> {1}",
                Console.WriteLine("Successful complete -> {0}%", batteryPercentage);


answered by user Jolie Ann
selected by user golearnweb