Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Cake_While_loop_exercise
- {
- class Program
- {
- static void Main(string[] args)
- {
- int width = int.Parse(Console.ReadLine());
- int length = int.Parse(Console.ReadLine());
- int cakeSize = width * length;
- string command = Console.ReadLine();
- int piecesSize = 0;
- while (command != "STOP")
- {
- piecesSize += int.Parse(command);
- if (piecesSize >= cakeSize)
- {
- Console.WriteLine($"No more cake left! You need {piecesSize-cakeSize} pieces more.");
- return;
- }
- command = Console.ReadLine();
- }
- Console.WriteLine($"{cakeSize-piecesSize} pieces are left.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment