Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp23
- {
- class Program
- {
- static void Main(string[] args)
- {
- double budget = double.Parse(Console.ReadLine());
- int countOfBoughtProducts = 0;
- double priceOfBoughtProdurcts = 0;
- double productPrice = 0;
- while (budget >= productPrice)
- {
- string productName = Console.ReadLine();
- if (productName == "Stop")
- {
- Console.WriteLine($"You bought {countOfBoughtProducts} products for {priceOfBoughtProdurcts:f2} leva.");
- break;
- }
- productPrice = double.Parse(Console.ReadLine());
- if (productName != "Stop")
- {
- countOfBoughtProducts++;
- if (countOfBoughtProducts == 3)
- {
- productPrice = productPrice / 2;
- }
- priceOfBoughtProdurcts += productPrice;
- budget -= productPrice;
- }
- }
- if (budget < productPrice)
- {
- Console.WriteLine("You don't have enough money!");
- Console.WriteLine($"You need {Math.Abs(budget):f2} leva!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement