Advertisement
IvanBorisovG

Cake

Sep 5th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. int cakeWidth = int.Parse(Console.ReadLine());
  2.             int cakeLenght = int.Parse(Console.ReadLine());
  3.             int allPieces = cakeLenght * cakeWidth;
  4.             string str = Console.ReadLine();
  5.             int grabbedPieces = 0;
  6.             while ((str != "STOP") && (allPieces >= 0))
  7.             {
  8.                 grabbedPieces = int.Parse(str);
  9.                 allPieces -= grabbedPieces;
  10.                 if (allPieces >= 0)
  11.                 {
  12.                     str = Console.ReadLine();
  13.                 }
  14.             }
  15.             if (str == "STOP" && allPieces > 0)
  16.             {
  17.                 Console.WriteLine($"{allPieces} pieces are left.");
  18.             }
  19.             else
  20.             {
  21.                 if (allPieces <= 0)
  22.                 {
  23.                     Console.WriteLine($"No more cake left! You need {Math.Abs(allPieces)} pieces more.");
  24.                 }
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement