Advertisement
v4m4v4

SoftUniBarIncome

Sep 30th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. namespace p03._01.SoftUniBarIncome
  2. {
  3.     using System;
  4.     using System.Linq;
  5.     using System.Text.RegularExpressions;
  6.  
  7.     class SoftUniBarIncome
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.  
  13.             //Regex pattern = new Regex
  14.             //(
  15.             //    @"%(?<name>[A-Z][a-z]+)%[^\.\|\$%]*<(?<product>.+)>[^\.\|\$%]*\|(?<count>\d+)\|[^\.\|\$%]*(?<price>[1-9]+\d*\.?\d+?)\$"
  16.             //);
  17.             string pattern = @"%(?<name>[A-Z][a-z]+)%[^\.\|\$%]*<(?<product>.+)>[^\.\|\$%]*\|(?<count>\d+)\|[^\.\|\$%]*(?<price>[1-9]+\d*\.?\d+?)\$";
  18.  
  19.             double totalSum = 0.0;
  20.  
  21.             while (input.Equals("end of shift") == false)
  22.             {
  23.                 //Match matchIncome = pattern.Match(input);
  24.                 if (Regex.IsMatch(input, pattern))
  25.                 //if (matchIncome.Success)
  26.                 {
  27.                     Match matchIncome = Regex.Match(input, pattern);
  28.  
  29.                     string name = matchIncome.Groups["name"].Value;
  30.                     string product = matchIncome.Groups["product"].Value;
  31.                     int count = int.Parse(matchIncome.Groups["count"].Value);
  32.                     double price = double.Parse(matchIncome.Groups["price"].Value);
  33.        
  34.                     double sum = count * price;
  35.                     totalSum += sum;
  36.                    
  37.                     Console.WriteLine(
  38.                         $"{name}: {product} - {sum:F2}");
  39.                 }
  40.  
  41.                 input = Console.ReadLine();
  42.             }
  43.  
  44.             Console.WriteLine($"Total income: {totalSum:F2}");
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement