Advertisement
desislava_topuzakova

04. Tourist Shop

Jul 18th, 2020
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4. namespace _02._Odd_Occurrences
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             double budget = double.Parse(Console.ReadLine());
  11.             string productName = Console.ReadLine(); //име на продукт или "Stop"
  12.             int countBoughtProducts = 0;
  13.             double totalPrice = 0;
  14.  
  15.             while (productName != "Stop")
  16.             {
  17.                 //име на продукт
  18.                 //цена на продукта
  19.                 double productPrice = double.Parse(Console.ReadLine());
  20.                 countBoughtProducts++;
  21.                 //1. проверка дали е трети продукт
  22.                 if (countBoughtProducts % 3 == 0)
  23.                 {
  24.                     productPrice /= 2;
  25.                 }
  26.                 //2. купим
  27.                 budget -= productPrice;
  28.                 totalPrice += productPrice;
  29.                 //3. достатъчен ли е бюджета
  30.  
  31.                 if (budget < 0)
  32.                 {
  33.                     Console.WriteLine("You don't have enough money!");
  34.                     Console.WriteLine($"You need {Math.Abs(budget):F2} leva!");
  35.                     break;
  36.                 }
  37.                productName = Console.ReadLine();
  38.  
  39.             }
  40.  
  41.             if (productName == "Stop")
  42.             {
  43.                 Console.WriteLine($"You bought {countBoughtProducts} products for {totalPrice:F2} leva.");
  44.             }
  45.  
  46.  
  47.  
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement