Advertisement
petyaminkova91

Untitled

Nov 22nd, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _01_Furniture
  5. {
  6. class Furniture
  7. {
  8. static void Main(string[] args)
  9. {
  10. var pattern = @">{2}(?<furniture>[A-Za-z]+)<{2}(?<price>\d+.?\d*)!(?<quantity>\d+)";
  11.  
  12. var input = Console.ReadLine();
  13. var text = String.Empty;
  14.  
  15. while (input != "Purchase")
  16. {
  17. text += input;
  18. input = Console.ReadLine();
  19. }
  20.  
  21. var regex = new Regex(pattern);
  22.  
  23. var furnitures = regex.Matches(text);
  24.  
  25. var totalPrice = 0.0;
  26.  
  27. Console.WriteLine("Bought furniture:");
  28. foreach (Match furniture in furnitures)
  29. {
  30. var currentFurniture = furniture.Groups["furniture"].Value;
  31. var currentPrice = double.Parse(furniture.Groups["price"].Value);
  32. var quantity = int.Parse(furniture.Groups["quantity"].Value);
  33.  
  34. totalPrice += currentPrice * quantity;
  35.  
  36. Console.WriteLine(currentFurniture);
  37. }
  38.  
  39. Console.WriteLine($"Total money spend: {totalPrice:f2}");
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement