Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06Cake
  4. {
  5.     class Cake
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int cakeWidth = int.Parse(Console.ReadLine());
  10.             int cakeHeight = int.Parse(Console.ReadLine());
  11.  
  12.             int cakePieces = cakeWidth * cakeHeight;
  13.  
  14.             int takenPieces = 0;
  15.             int eatenPieces = 0;
  16.             string command = Console.ReadLine();
  17.             command = command.ToUpper();
  18.  
  19.             while (command != "STOP")
  20.             {
  21.                 takenPieces = int.Parse(command);
  22.                 eatenPieces += takenPieces;
  23.                 if (cakePieces <= eatenPieces)
  24.                 {
  25.                     cakePieces = Math.Abs(cakePieces - eatenPieces);
  26.                     Console.WriteLine($"No more cake left! You need {cakePieces} pieces more.");
  27.                     break;
  28.                 }
  29.                 command = Console.ReadLine();
  30.             }
  31.             if (command == "STOP")
  32.             {
  33.                 cakePieces = cakePieces - eatenPieces;
  34.                 Console.WriteLine($"{cakePieces} pieces are left.");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement