Guest User

04. Коледна Статистика

a guest
Jan 29th, 2019
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 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.  
  7. namespace Exam_11_12
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.  
  15.             int beveragesCount = 0;
  16.             int sweetsCount = 0;
  17.             int presentsCount = 0;
  18.             int othersCount = 0;
  19.  
  20.             double beveragesTotalPrice = 0.0;
  21.             double sweetsTotalPrice = 0.0;
  22.             double presentsTotalPrice = 0.0;
  23.             double othersTotalPrice = 0;
  24.  
  25.             for (int i = 0; i < n; i++)
  26.             {
  27.                 string currentProduct = Console.ReadLine();
  28.                 double currentPrice = double.Parse(Console.ReadLine());
  29.                 double currentQuantity = double.Parse(Console.ReadLine());
  30.  
  31.                 switch (currentProduct)
  32.                 {
  33.                     case "cola":
  34.                     case "wine":
  35.                         beveragesCount++;
  36.                         beveragesTotalPrice += currentPrice * currentQuantity;
  37.                         break;
  38.                     case "baklavichka":
  39.                     case "cupcake":
  40.                         sweetsCount++;
  41.                         sweetsTotalPrice += currentPrice * currentQuantity;
  42.                         break;
  43.                     case "flower":
  44.                     case "chocolates":
  45.                     case "book":
  46.                         presentsCount++;
  47.                         presentsTotalPrice += currentPrice * currentQuantity;
  48.                         break;
  49.                     default:
  50.                         othersCount++;
  51.                         othersTotalPrice += currentPrice * currentQuantity;
  52.                         break;
  53.                 }
  54.             }
  55.  
  56.             double totalMoneySpend = beveragesTotalPrice + sweetsTotalPrice + presentsTotalPrice + othersTotalPrice;
  57.             double sweetsPercentage = sweetsTotalPrice / totalMoneySpend * 100;
  58.             double beveragesPercentage = beveragesTotalPrice / totalMoneySpend * 100;
  59.             double presentsPercentage = presentsTotalPrice / totalMoneySpend * 100;
  60.             double othersPercentage = othersTotalPrice / totalMoneySpend * 100;
  61.  
  62.             Console.WriteLine($"Total money spent: {totalMoneySpend:f2}");
  63.             Console.WriteLine($"Money spent on: Sweets - {sweetsPercentage:f2}%; Beverages - {beveragesPercentage:f2}%; Presents - {presentsPercentage:f2}%;");
  64.             Console.WriteLine($"Money spent on other products: {othersTotalPrice:f2} or {othersPercentage:f2}%");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment