Advertisement
Evtim_stefanovWNR

Coffee prices

Sep 27th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Numerics;
  7. namespace CoffeeOrders
  8. {
  9.     class CoffeeCost
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int N = int.Parse(Console.ReadLine());
  14.             Dictionary<DateTime,int> Dictionary = new Dictionary<DateTime,int>();
  15.             DateTime[] newdDateTime=new DateTime[N];
  16.             int[] numberofPills = new int[N];
  17.             int[] numberofDays = new int[N];
  18.             decimal[] initialprices=new decimal[N];
  19.             decimal[] prices = new decimal[N];
  20.             decimal totalPrice = 0;
  21.             for (int i = 0; i < N; i++)
  22.             {
  23.                 initialprices[i] = decimal.Parse(Console.ReadLine());
  24.                 Dictionary.Add(DateTime.ParseExact(Console.ReadLine(),"d/M/yyyy",null), int.Parse(Console.ReadLine())); //Add key/value pairs to dictionary
  25.                 foreach(KeyValuePair<DateTime,int> pair in Dictionary)
  26.                 {
  27.                     numberofPills[i]=pair.Value; //assing KeyValue p
  28.                 }
  29.                 foreach (KeyValuePair<DateTime, int> secondpair in Dictionary)
  30.                 {
  31.                     numberofDays[i] = DateTime.DaysInMonth(secondpair.Key.Year,secondpair.Key.Month); //get DaysInMonth via passing keyvaluepair Key and Value as arguments
  32.                 }  
  33.                 prices[i] += ((decimal)numberofDays[i] * (decimal)numberofPills[i] * initialprices[i]); //calculate prices for coffee
  34.                 totalPrice += prices[i];  
  35.              
  36.             }    
  37.             for (int j = 0; j < N; j++)
  38.             {
  39.                 Console.WriteLine("The price for the coffee is: ${0:0.00}", Math.Round(prices[j],2));
  40.                
  41.             }
  42.             Console.WriteLine("Total: ${0:0.00}",Math.Round(totalPrice,2));
  43.            
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement