Advertisement
Niicksana

Cake

Dec 13th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 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 _4.Cake
  8. {
  9.     class Cake
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // Exam - 03 September 2017
  14.             double width = double.Parse(Console.ReadLine());
  15.             double length = double.Parse(Console.ReadLine());
  16.  
  17.             double cake = width * length;
  18.             double cntPieces = cake;
  19.  
  20.             while (cntPieces >= 0)
  21.             {
  22.                 {
  23.                     try
  24.                     {
  25.                         int pieces = int.Parse(Console.ReadLine());
  26.                         cntPieces -= pieces;
  27.                     }
  28.  
  29.                     catch
  30.                     {
  31.                         break;
  32.                     }
  33.                 }
  34.             }
  35.  
  36.             if (cntPieces >= 0)
  37.             {
  38.                 Console.WriteLine("{0} pieces are left.", cntPieces);
  39.             }
  40.  
  41.             else
  42.             {
  43.                 Console.WriteLine("No more cake left! You need {0} pieces more.", Math.Abs(cntPieces));
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement