Advertisement
TeMePyT

Untitled

May 30th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 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 Problem_7.Inventory_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[] command = Console.ReadLine().Split(' ').ToArray();
  17. while (command[0] != "done")
  18. {
  19. string product = command[0];
  20. long quantityOrdered = long.Parse(command[1]);
  21. int indexOfProduct = Array.IndexOf(products, product);
  22. decimal productPrice = price[indexOfProduct];
  23. long productQuantity = 0;
  24. try
  25. {
  26. productQuantity = quantity[indexOfProduct];
  27. }
  28. catch (Exception )
  29. {
  30. productQuantity = 0;
  31. }
  32.  
  33. if (quantityOrdered > productQuantity)
  34. {
  35. Console.WriteLine($"We do not have enough {product}");
  36. }
  37. else
  38. {
  39. decimal totalPrice = quantityOrdered * productPrice;
  40. Console.WriteLine($"{product} x {quantityOrdered} costs {totalPrice:f2}");
  41. quantity[indexOfProduct] -= quantityOrdered;
  42. }
  43.  
  44. command = Console.ReadLine().Split(' ').ToArray();
  45. }
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement