Advertisement
Guest User

Kendrik Lamar

a guest
Nov 18th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 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 cake
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var cakeWidth = int.Parse(Console.ReadLine());
  14.             var cakeLength = int.Parse(Console.ReadLine());
  15.             var pieces = cakeLength * cakeWidth;
  16.  
  17.             do
  18.             {
  19.                 var number = Console.ReadLine();
  20.  
  21.                 if (number != "STOP")
  22.                 {
  23.                     int.TryParse(number, out int numberInt);
  24.                     pieces -= numberInt;
  25.  
  26.                 }
  27.                 else if (number == "STOP")
  28.                 {
  29.                     break;
  30.                 }
  31.                
  32.             } while (pieces >= 0);
  33.  
  34.             if (pieces > 0)
  35.             {
  36.                 Console.WriteLine($"{pieces} pieces are left.");
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine($"No more cake left! You need {Math.Abs(pieces)} pieces more.");
  41.             }
  42.  
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement