Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ShopBill
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Enter data
- Console.WriteLine("Please enter on single line, with space:\nquantity, type of product and price of products!");
- //will store midlle bill in List<double> and generaly in Dictionary with int [count num of product] Dict<string, double>
- try
- {
- List<double> midlle = new List<double>();
- Dictionary<int, Dictionary<string, double>> dict = new Dictionary<int, Dictionary<string, double>>();
- var counter = 0;
- while (true)
- {
- //Quantity, type and price
- var inputData = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();
- if (inputData[0] == "Finish")
- {
- break;
- }
- var quantity = int.Parse(inputData[0]);
- var nameOfProduct = inputData[1];
- var price = double.Parse(inputData[2]);
- double sum = quantity * price;
- midlle.Add(sum);
- counter++;
- Dictionary<string, double> current = new Dictionary<string, double>();
- current.Add(nameOfProduct, sum);
- dict.Add(counter, current);
- }
- foreach (var item in dict)
- {
- Console.Write($"Nomer {item.Key}. ");
- foreach (var i in item.Value)
- {
- Console.WriteLine("Product: " + i.Key + "; Price: " + i.Value);
- }
- }
- var total = midlle.Sum();
- Console.WriteLine($"Total: {total:f2} lv");
- }
- catch (Exception)
- {
- Console.WriteLine("Error! Please enter data again!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement