Advertisement
silvana1303

baking competition

May 2nd, 2020
698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace exampreparation
  4. {
  5.     class exam
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int contestants = int.Parse(Console.ReadLine());
  10.             int pastrySum = 0;
  11.             double charitySum = 0.0;
  12.            
  13.  
  14.             for (int i = 0; i < contestants; i++)
  15.             {
  16.                 string name = Console.ReadLine();
  17.                 string command = Console.ReadLine();
  18.  
  19.                 double price = 0.0;
  20.                 int cookies = 0;
  21.                 int cakes = 0;
  22.                 int waffles = 0;
  23.  
  24.                 while (command != "Stop baking!")
  25.                 {
  26.                    
  27.                     string pastry = command;
  28.                     int pastryCount = int.Parse(Console.ReadLine());
  29.  
  30.                     pastrySum += pastryCount;
  31.  
  32.                     if (pastry == "cookies")
  33.                     {
  34.                         price = 1.50;
  35.                         cookies += pastryCount;
  36.                     }
  37.                     else if (pastry == "cakes")
  38.                     {
  39.                         price = 7.80;
  40.                         cakes += pastryCount;
  41.                     }
  42.                     else
  43.                     {
  44.                         price = 2.30;
  45.                         waffles += pastryCount;
  46.                     }
  47.  
  48.                     charitySum += price * pastryCount;
  49.  
  50.                     command = Console.ReadLine();
  51.  
  52.                 }
  53.  
  54.                 Console.WriteLine($"{name} baked {cookies} cookies, {cakes} cakes and {waffles} waffles.");
  55.             }
  56.  
  57.             Console.WriteLine($"All bakery sold: {pastrySum}");
  58.             Console.WriteLine($"Total sum for charity: {charitySum:f2} lv.");
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement