Advertisement
aggressiveviking

Untitled

Feb 20th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.TouristShop
  4. {
  5.     class TouristShop
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double budget = double.Parse(Console.ReadLine());
  10.             string nameProduct = Console.ReadLine();
  11.  
  12.             int countEquipment = 1;
  13.             double sumCost = 0;
  14.  
  15.             while (nameProduct != "Stop")
  16.             {
  17.                 double price = double.Parse(Console.ReadLine());
  18.  
  19.                 if (countEquipment % 3 == 0)
  20.                 {
  21.                     price /= 2;
  22.                 }
  23.  
  24.                 if (price > budget)
  25.                 {
  26.                     double needed = price - budget;
  27.                     Console.WriteLine($"You don't have enough money!");
  28.                     Console.WriteLine($"You need {needed:f2} leva!");
  29.                     break;
  30.                 }
  31.  
  32.                 countEquipment++;
  33.                 budget -= price;
  34.                 sumCost += price;
  35.  
  36.                 nameProduct = Console.ReadLine();
  37.             }
  38.  
  39.             if (nameProduct == "Stop")
  40.             {
  41.                 double fix = countEquipment - 1;
  42.                 Console.WriteLine($"You bought {fix} products for {sumCost:f2} leva.");
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement