Advertisement
EmoRz

ShopReciept

Jun 3rd, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ShopBill
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             //Enter data
  12.             Console.WriteLine("Please enter on single line, with space:\nquantity, type of product and price of products!");
  13.             //will store midlle bill in List<double> and generaly in Dictionary with int [count num of product] Dict<string, double>
  14.             try
  15.             {
  16.                 List<double> midlle = new List<double>();
  17.                 Dictionary<int, Dictionary<string, double>> dict = new Dictionary<int, Dictionary<string, double>>();
  18.                 var counter = 0;
  19.  
  20.                 while (true)
  21.                 {
  22.                     //Quantity, type and price
  23.                     var inputData = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();
  24.  
  25.                     if (inputData[0] == "Finish")
  26.                     {
  27.                         break;
  28.                     }
  29.                     var quantity = int.Parse(inputData[0]);
  30.                     var nameOfProduct = inputData[1];
  31.                     var price = double.Parse(inputData[2]);
  32.  
  33.                     double sum = quantity * price;
  34.                     midlle.Add(sum);
  35.                     counter++;
  36.                     Dictionary<string, double> current = new Dictionary<string, double>();
  37.                     current.Add(nameOfProduct, sum);
  38.                     dict.Add(counter, current);
  39.                 }
  40.                 foreach (var item in dict)
  41.                 {
  42.                     Console.Write($"Nomer {item.Key}. ");
  43.                     foreach (var i in item.Value)
  44.                     {
  45.                         Console.WriteLine("Product: " + i.Key + "; Price: " + i.Value);
  46.                     }
  47.  
  48.                 }
  49.                 var total = midlle.Sum();
  50.                 Console.WriteLine($"Total: {total:f2} lv");
  51.             }
  52.             catch (Exception)
  53.             {
  54.                 Console.WriteLine("Error! Please enter data again!");
  55.             }
  56.            
  57.         }
  58.  
  59.  
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement