Guest User

Untitled

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