Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 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.Supermarket_Database
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var productPrice = new Dictionary<string, double>();
  14. var productQuantite = new Dictionary<string, double>();
  15. double sum = 0;
  16. var productsName = Console.ReadLine().Split(' ').ToArray();
  17.  
  18. while (productsName[0] != "stocked")
  19. {
  20.  
  21. string product = productsName[0];
  22. double price = double.Parse(productsName[1]);
  23. int quantity = int.Parse(productsName[2]);
  24.  
  25.  
  26. productPrice[product] = price;
  27.  
  28. if (productQuantite.ContainsKey(product))
  29. {
  30. productQuantite[product] += quantity;
  31. }
  32. else
  33. {
  34. productQuantite[product] = quantity;
  35. }
  36.  
  37. productsName = Console.ReadLine().Split(' ').ToArray();
  38.  
  39.  
  40. }
  41. foreach (var kvp in productPrice)
  42. {
  43. Console.WriteLine($"{kvp.Key}: ${kvp.Value:f2} * {productQuantite[kvp.Key]} = ${(kvp.Value* productQuantite[kvp.Key]):F2}");
  44. sum += kvp.Value * productQuantite[kvp.Key];
  45. }
  46. Console.WriteLine(new string('-',30));
  47. Console.WriteLine($"Grand Total: ${sum:f2}");
  48.  
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement