TheBulgarianWolf

Furnitures

Apr 15th, 2021
447
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace Furniture
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Regex regex = new Regex(@">>(?<name>[A-Za-z]+)<<(?<price>\d+\.?\d*)!(?<quantity>\d+)");
  12.             List<string> furnitures = new List<string>();
  13.             double totalSum = 0;
  14.             while (true)
  15.             {
  16.                 string line = Console.ReadLine();
  17.                 if(line == "Purchase")
  18.                 {
  19.                     break;
  20.                 }
  21.  
  22.                 Match match = regex.Match(line);
  23.                 if (!match.Success)
  24.                 {
  25.                     continue;
  26.                 }
  27.  
  28.                 string name = match.Groups["name"].Value;
  29.                 double price = double.Parse(match.Groups["price"].Value);
  30.                 double quantity = int.Parse(match.Groups["quantity"].Value);
  31.                 furnitures.Add(name);
  32.                 totalSum += price * quantity;
  33.             }
  34.  
  35.             Console.WriteLine("Furnitures: ");
  36.             foreach(string f in furnitures)
  37.             {
  38.                 Console.WriteLine(f);
  39.             }
  40.             Console.WriteLine("Total price: {0:F2}", totalSum);
  41.         }
  42.     }
  43. }
  44.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×