Advertisement
VanessaShopping

Problem 02 - Beer Stock

Aug 26th, 2016
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.91 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 BeerStock
  8. {
  9.     class BeerStock
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int neededBeers = int.Parse(Console.ReadLine());
  14.             string line = Console.ReadLine();
  15.             int beersCout = 0;
  16.  
  17.  
  18.             int enoughtCases = 0;
  19.             int enoughtSixPacks = 0;
  20.             int enoughtBeers = 0;
  21.  
  22.             int notEnoughtCases = 0;
  23.             int notEnoughtSixPacks = 0;
  24.             int notEnoughtBeers = 0;
  25.             while (line != "Exam Over")
  26.             {
  27.                 string[] parameters = line.Split();
  28.                 int amount = int.Parse(parameters[0]);
  29.                 string type = parameters[1];
  30.                 switch (type)
  31.                 {
  32.                     case "cases":
  33.                         beersCout += amount * 24;
  34.                         break;
  35.                     case "sixpacks":
  36.                         beersCout += amount * 6;
  37.                         break;
  38.                     default:
  39.                         beersCout += amount;
  40.                         break;
  41.                 }
  42.                 line = Console.ReadLine();
  43.             }
  44.  
  45.             if (beersCout >= neededBeers)
  46.                 beersCout = beersCout - (beersCout / 100);
  47.  
  48.             if (beersCout >= neededBeers)
  49.             {
  50.                 int leftBeers = beersCout - neededBeers;
  51.                 if (leftBeers >= 24)
  52.                 {
  53.                     enoughtCases = leftBeers / 24;
  54.                     leftBeers = leftBeers - (enoughtCases * 24);
  55.                 }
  56.                 if (leftBeers >= 6)
  57.                 {
  58.                     enoughtSixPacks = leftBeers / 6;
  59.                     leftBeers = leftBeers - (enoughtSixPacks * 6);
  60.                 }
  61.                 if (leftBeers >= 1)
  62.                 {
  63.                     enoughtBeers = leftBeers;
  64.                 }
  65.                 Console.WriteLine($"Cheers! Beer left: {enoughtCases} cases, {enoughtSixPacks} sixpacks and {enoughtBeers} beers.");
  66.             }
  67.  
  68.             else
  69.             {
  70.                 int leftBeers = neededBeers - beersCout;
  71.                 if (leftBeers >= 24)
  72.                 {
  73.                     notEnoughtCases = leftBeers / 24;
  74.                     leftBeers = leftBeers - (notEnoughtCases * 24);
  75.                 }
  76.                 if (leftBeers >= 6)
  77.                 {
  78.                     notEnoughtSixPacks = leftBeers / 6;
  79.                     leftBeers = leftBeers - (notEnoughtSixPacks * 6);
  80.                 }
  81.                 if (leftBeers >= 1)
  82.                 {
  83.                     notEnoughtBeers = leftBeers;
  84.                 }
  85.                 Console.WriteLine($"Not enough beer. Beer needed: {notEnoughtCases} cases, {notEnoughtSixPacks} sixpacks and {notEnoughtBeers} beers.");
  86.             }
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement