tod36

SoftUni cake

Nov 18th, 2019
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _18_11_2019_cake
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.            
  10.             int cakeWidth = int.Parse(Console.ReadLine());
  11.             int cakeLength = int.Parse(Console.ReadLine());
  12.             int cakeSize = cakeLength * cakeWidth;
  13.             int cakeNumber = 0;
  14.             string input = "";
  15.             int piecesLeft = 0;
  16.             int piecesNeed = 0;
  17.  
  18.             while (cakeSize > cakeNumber)
  19.             {
  20.                 input = Console.ReadLine();
  21.  
  22.                 if (input == "STOP")
  23.                 {
  24.                     piecesLeft = cakeSize - cakeNumber;
  25.                     Console.WriteLine($"{piecesLeft} pieces are left.");
  26.                     return;
  27.                 }
  28.                 else cakeNumber += int.Parse(input);
  29.                
  30.             }
  31.             if (cakeNumber >= cakeSize)
  32.             {
  33.                 piecesNeed = cakeNumber - cakeSize;
  34.                 Console.WriteLine($"No more cake left! You need {piecesNeed} pieces more.");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment