Advertisement
Guest User

Untitled

a guest
May 9th, 2019
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 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 ConsoleApp23
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             double budget = double.Parse(Console.ReadLine());
  14.  
  15.             int countOfBoughtProducts = 0;
  16.             double priceOfBoughtProdurcts = 0;
  17.             double productPrice = 0;
  18.  
  19.             while (budget >= productPrice)
  20.             {
  21.                 string productName = Console.ReadLine();
  22.  
  23.                 if (productName == "Stop")
  24.                 {
  25.                     Console.WriteLine($"You bought {countOfBoughtProducts} products for {priceOfBoughtProdurcts:f2} leva.");
  26.                     break;
  27.                 }
  28.  
  29.                  productPrice = double.Parse(Console.ReadLine());
  30.  
  31.                 if (productName != "Stop")
  32.                 {
  33.                    
  34.                     countOfBoughtProducts++;
  35.  
  36.                     if (countOfBoughtProducts == 3)
  37.                     {
  38.                         productPrice = productPrice / 2;
  39.                     }
  40.  
  41.                     priceOfBoughtProdurcts += productPrice;
  42.                     budget -= productPrice;
  43.  
  44.                 }
  45.  
  46.                
  47.             }
  48.  
  49.  
  50.              if (budget < productPrice)
  51.             {
  52.                 Console.WriteLine("You don't have enough money!");
  53.                 Console.WriteLine($"You need {Math.Abs(budget):f2} leva!");
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement