Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Problem_7.Inventory_Matcher
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] products = Console.ReadLine().Split(' ').ToArray();
- long[] quantity = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
- decimal[] price = Console.ReadLine().Split(' ').Select(decimal.Parse).ToArray();
- string[] command = Console.ReadLine().Split(' ').ToArray();
- while (command[0] != "done")
- {
- string product = command[0];
- long quantityOrdered = long.Parse(command[1]);
- int indexOfProduct = Array.IndexOf(products, product);
- decimal productPrice = price[indexOfProduct];
- long productQuantity = 0;
- try
- {
- productQuantity = quantity[indexOfProduct];
- }
- catch (Exception )
- {
- productQuantity = 0;
- }
- if (quantityOrdered > productQuantity)
- {
- Console.WriteLine($"We do not have enough {product}");
- }
- else
- {
- decimal totalPrice = quantityOrdered * productPrice;
- Console.WriteLine($"{product} x {quantityOrdered} costs {totalPrice:f2}");
- quantity[indexOfProduct] -= quantityOrdered;
- }
- command = Console.ReadLine().Split(' ').ToArray();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement