MiroslavKisov

CoffeeOrders

Nov 5th, 2017
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _01.SoftuniCoffeeOrders
  9. {
  10.     public class StartUp
  11.     {
  12.         public static void Main()
  13.         {
  14.             long N = long.Parse(Console.ReadLine());
  15.             decimal totalPrice = 0.0m;
  16.             for (int i = 0; i < N; i++)
  17.             {
  18.                 decimal pricePerCapsule = decimal.Parse(Console.ReadLine());
  19.                 string orderDate = Console.ReadLine();
  20.                 long capsulesCount = long.Parse(Console.ReadLine());
  21.                 DateTime date = DateTime.ParseExact(orderDate, "d/M/yyyy", CultureInfo.InstalledUICulture);
  22.                 var dateSplitted = orderDate.Split('/').ToArray();
  23.                 int year = int.Parse(dateSplitted[2]);
  24.                 int month = int.Parse(dateSplitted[1]);
  25.                 long numberOfDays = DateTime.DaysInMonth(year, month);
  26.                 long pricePerMonth = numberOfDays * capsulesCount;
  27.                 decimal currentPrice = pricePerMonth * pricePerCapsule;
  28.                 Console.WriteLine($"The price for the coffee is: ${currentPrice:F2}");
  29.                 totalPrice += currentPrice;
  30.             }
  31.             Console.WriteLine($"Total: ${totalPrice:F2}");
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment