Aliendreamer

cake programing basics

Feb 17th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.     class Program
  5.     {
  6.         static void Main()
  7.         {
  8.             int length = int.Parse(Console.ReadLine());
  9.             int width = int.Parse(Console.ReadLine());
  10.             int cake = length * width;
  11.             string input;
  12.             bool cakeleft=true;
  13.             while ((input=Console.ReadLine())!= "Stop" && cakeleft)
  14.             {
  15.                  int  pieces = int.Parse(input);
  16.                  cake -= pieces;
  17.                  cakeleft = cake - pieces > 0;
  18.             }
  19.  
  20.             if (input == "Stop")
  21.             {
  22.                 Console.WriteLine("{0} pieces are left.",cake);
  23.             }
  24.             else
  25.             {
  26.                 Console.WriteLine("No more cake left.You need {0} piece more.",Math.Abs(cake));
  27.             }
  28.  
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment