Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace StringAndRegex
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. string pattern = @"%(?<customer>[A-Z][a-z]+)%[^|$%.]*<(?<product>\w+)>[^|$%.]*\|(?<count>\d+)\|[^|$%.]*?(?<price>[0-9]+\.?[0-9]+)\$";
  14.  
  15. string input = String.Empty;
  16. double totalIncome = 0.0;
  17.  
  18. while ((input = Console.ReadLine()) != "end of shift")
  19. {
  20. Regex order = new Regex(pattern);
  21.  
  22. if (order.IsMatch(input))
  23. {
  24.  
  25. string customerName = order.Match(input).Groups["customer"].Value;
  26. string productName = order.Match(input).Groups["product"].Value;
  27. int count = int.Parse(order.Match(input).Groups["count"].Value);
  28. double price = double.Parse(order.Match(input).Groups["price"].Value);
  29.  
  30. double totalPrice = price * count;
  31.  
  32. totalIncome += totalPrice;
  33.  
  34. Console.WriteLine($"{customerName}: {productName} - {totalPrice:F2}");
  35.  
  36. }
  37.  
  38. }
  39.  
  40. Console.WriteLine($"Total income: {totalIncome:F2}");
  41.  
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement