alexbancheva

Cake_While_Loop

Nov 16th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Cake_While_loop_exercise
  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 cakeSize = width * length;
  13. string command = Console.ReadLine();
  14. int piecesSize = 0;
  15.  
  16. while (command != "STOP")
  17. {
  18.  
  19. piecesSize += int.Parse(command);
  20.  
  21. if (piecesSize >= cakeSize)
  22. {
  23. Console.WriteLine($"No more cake left! You need {piecesSize-cakeSize} pieces more.");
  24. return;
  25. }
  26. command = Console.ReadLine();
  27. }
  28.  
  29. Console.WriteLine($"{cakeSize-piecesSize} pieces are left.");
  30.  
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment