Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace P12SoftUni_Bar_Income
- {
- class Program
- {
- static void Main(string[] args)
- {
- string regex = @"%(?<name>[A-Z][a-z]+)%[^|$%.]*<(?<product>[\w]+)>[^|$%.]*\|(?<count>[\d]+)\|[^|$%.]*?(?<price>[\d]+\.?[\d]+)\$";
- double totalIncome = 0;
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end of shift")
- {
- break;
- }
- var match = Regex.Match(input, regex);
- if (match.Success)
- {
- int count = int.Parse(match.Groups["count"].Value);
- double totalPrice = double.Parse(match.Groups["price"].Value) * count;
- totalIncome += totalPrice;
- Console.WriteLine($"{match.Groups["name"].Value}: {match.Groups["product"].Value} - {totalPrice:F2}");
- }
- }
- Console.WriteLine($"Total income: {totalIncome:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment