reking12

Untitled

Mar 26th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace P12SoftUni_Bar_Income
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string regex = @"%(?<name>[A-Z][a-z]+)%[^|$%.]*<(?<product>[\w]+)>[^|$%.]*\|(?<count>[\d]+)\|[^|$%.]*?(?<price>[\d]+\.?[\d]+)\$";
  11.             double totalIncome = 0;
  12.             while (true)
  13.             {
  14.                
  15.                 string input = Console.ReadLine();
  16.                 if (input == "end of shift")
  17.                 {
  18.                     break;
  19.                 }
  20.                 var match = Regex.Match(input, regex);
  21.                 if (match.Success)
  22.                 {
  23.                     int count = int.Parse(match.Groups["count"].Value);
  24.                     double totalPrice = double.Parse(match.Groups["price"].Value) * count;
  25.                     totalIncome += totalPrice;
  26.                     Console.WriteLine($"{match.Groups["name"].Value}: {match.Groups["product"].Value} - {totalPrice:F2}");
  27.                 }
  28.             }
  29.             Console.WriteLine($"Total income: {totalIncome:f2}");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment