Advertisement
Arxero

Untitled

Nov 8th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 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 _28.Upgraded_Matcher
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] products = Console.ReadLine().Split().ToArray();
  14.             long[] quantity = Console.ReadLine().Split().Select(long.Parse).ToArray();
  15.             decimal[] price = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
  16.             string[] productPlusOrder = Console.ReadLine().Split().ToArray();
  17.  
  18.             long quantityChecker = 0;
  19.  
  20.             while (productPlusOrder[0] != "done")
  21.             {
  22.                 long productIndex = Array.IndexOf(products, productPlusOrder[0]);
  23.                 long order = long.Parse(productPlusOrder[1]);
  24.                 decimal totalPrice = 0;
  25.  
  26.                 //find out what quantity we have of certain product
  27.                 for (long i = 0; i < quantity.Length; i++)
  28.                 {
  29.                     if (i == productIndex)
  30.                     {
  31.                         quantityChecker = quantity[productIndex];
  32.                     }
  33.                 }
  34.  
  35.                 if (quantityChecker >= order)
  36.                 {
  37.                     totalPrice = order * price[productIndex];
  38.                     quantity[productIndex] -= order;
  39.                     Console.WriteLine($"{products[productIndex]} x {order} costs {totalPrice:f2}");
  40.                 }
  41.                 else
  42.                 {
  43.                     Console.WriteLine($"We do not have enough {products[productIndex]}");
  44.  
  45.                 }
  46.                 productPlusOrder = Console.ReadLine().Split().ToArray();
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement