Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _4.Supermarket_Database
- {
- class Program
- {
- static void Main(string[] args)
- {
- var productPrice = new Dictionary<string, double>();
- var productQuantite = new Dictionary<string, double>();
- double sum = 0;
- var productsName = Console.ReadLine().Split(' ').ToArray();
- while (productsName[0] != "stocked")
- {
- string product = productsName[0];
- double price = double.Parse(productsName[1]);
- int quantity = int.Parse(productsName[2]);
- productPrice[product] = price;
- if (productQuantite.ContainsKey(product))
- {
- productQuantite[product] += quantity;
- }
- else
- {
- productQuantite[product] = quantity;
- }
- productsName = Console.ReadLine().Split(' ').ToArray();
- }
- foreach (var kvp in productPrice)
- {
- Console.WriteLine($"{kvp.Key}: ${kvp.Value:f2} * {productQuantite[kvp.Key]} = ${(kvp.Value* productQuantite[kvp.Key]):F2}");
- sum += kvp.Value * productQuantite[kvp.Key];
- }
- Console.WriteLine(new string('-',30));
- Console.WriteLine($"Grand Total: ${sum:f2}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement