Advertisement
riff-raff

03. SoftUni Bar Income

Aug 23rd, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace _03.Softuni_Bar
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = "";
  12.             string customerName = "";
  13.             string product = "";
  14.             long count = 0;
  15.             double price = 0;
  16.             double totalPrice = count * price;
  17.             double totalIncome = 0;
  18.  
  19.             List<string> list = new List<string>();
  20.  
  21.             bool isBreak = true;
  22.  
  23.             while (isBreak)
  24.             {
  25.                 input = Console.ReadLine();
  26.                 string pattern2 = @"%(?<customer>[A-Z][a-z]+)%[^\|\$%\.]*<(?<product>\w+)>[^\|\$%\.]*\|(?<count>\d)\|([^\|\$%\.]*\|)?(?<price>[0-9]+\.?[0-9]+)\$";
  27.                 var matches = Regex.Matches(input, pattern2);
  28.  
  29.                 if (input == "end of shift")
  30.                 {
  31.                     isBreak = false;
  32.                 }
  33.                 else
  34.                 {
  35.                     foreach (Match word in matches)
  36.                     {
  37.                         customerName = word.Groups["customer"].Value;
  38.                         product = word.Groups["product"].Value;
  39.                         count = long.Parse(word.Groups["count"].Value);
  40.                         price = double.Parse(word.Groups["price"].Value);
  41.                         totalPrice = count * price;
  42.                         list.Add($"{customerName}: {product} - {totalPrice:f2}");
  43.                         totalIncome += totalPrice;
  44.                     }
  45.                 }
  46.             }
  47.             Console.WriteLine(string.Join(Environment.NewLine,list));
  48.             Console.WriteLine($"Total income: {totalIncome:f2}");
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement