dragonbs

Cake

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