Advertisement
Dianov

While Loop - Exercise (06. Cake (not included in final score))

Dec 30th, 2020
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Cake
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int width = int.Parse(Console.ReadLine());
  14.             int length = int.Parse(Console.ReadLine());
  15.             int area = width * length;
  16.             int areaLeft = area;
  17.             int piecesCounter = 0;
  18.  
  19.             while (areaLeft > 0)
  20.             {
  21.                 string input = Console.ReadLine();
  22.                 if (input == "STOP")
  23.                 {
  24.                     Console.WriteLine($"{(area - piecesCounter)} pieces are left.");
  25.                     Environment.Exit(0);
  26.                 }
  27.                 piecesCounter += int.Parse(input);
  28.                 areaLeft -= int.Parse(input);
  29.             }
  30.             Console.WriteLine($"No more cake left! You need {(piecesCounter - area)} pieces more.");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement