Advertisement
silvana1303

cake

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