Advertisement
pjordanov

06. Cake ( While loop )

Jan 23rd, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Training_Cake_23_01_2019
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int l = int.Parse(Console.ReadLine());
  14.             int w = int.Parse(Console.ReadLine());
  15.             string comand = Console.ReadLine();
  16.  
  17.             int valueOfCake = l * w;
  18.             int peeceCounter = 0;
  19.  
  20.             while (comand != "STOP")
  21.             {
  22.                 peeceCounter += int.Parse(comand);
  23.  
  24.                 if (peeceCounter > valueOfCake)
  25.                 {
  26.                     Console.WriteLine($"No more cake left! You need {peeceCounter - valueOfCake} pieces more.");
  27.                     break;
  28.                 }
  29.                 comand = Console.ReadLine();
  30.             }
  31.             if (comand == "STOP")
  32.             {
  33.                 Console.WriteLine($"{valueOfCake - peeceCounter} pieces are left.");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement