kvadrat4o

SupermarketDataBase

Jun 16th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. /*
  2.  * Created by SharpDevelop.
  3.  * User: DVasilev
  4.  * Date: 2017/06/16
  5.  * Time: 10:54 AM
  6.  *
  7.  * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8.  */
  9. using System;
  10. using System.Linq;
  11. using System.Collections.Generic;
  12.  
  13.  
  14. namespace SupermarketDatabase
  15. {
  16.     class Program
  17.     {
  18.         public static void Main(string[] args)
  19.         {
  20.             //Console.WriteLine("Hello World!");
  21.             var database = new SortedDictionary<string, SortedDictionary<double,double>>();
  22.            
  23.             var commands = Console.ReadLine().Split(' ').ToList();
  24.             var command = commands[0];
  25.             while (command != "stocked")
  26.             {
  27.                 var stock = commands[1];
  28.                 if (!database.ContainsKey(stock))
  29.                 {
  30.                     database[stock] = new SortedDictionary<double,double>();
  31.                 }
  32.                 var price = double.Parse(commands[2]);
  33.                 var quantity = double.Parse(commands[3]);
  34.                 var total = price*quantity;
  35.                 foreach (var item in database)
  36.                 {
  37.                     Console.WriteLine("{0}: ${1:F2} * {2} = ${3:F2}",stock,price,quantity,total);
  38.                 }
  39.                 var totalSum = total;
  40.                 if (command == "stocked")
  41.                 {
  42.                     Console.WriteLine("{0}\nGrand Total: ${1:F2}", new String('-',30),totalSum);
  43.                 }
  44.             }
  45.             Console.Write("Press any key to continue . . . ");
  46.             Console.ReadKey(true);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment