Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _02._Odd_Occurrences
- {
- class Program
- {
- static void Main(string[] args)
- {
- double budget = double.Parse(Console.ReadLine());
- string productName = Console.ReadLine(); //име на продукт или "Stop"
- int countBoughtProducts = 0;
- double totalPrice = 0;
- while (productName != "Stop")
- {
- //име на продукт
- //цена на продукта
- double productPrice = double.Parse(Console.ReadLine());
- countBoughtProducts++;
- //1. проверка дали е трети продукт
- if (countBoughtProducts % 3 == 0)
- {
- productPrice /= 2;
- }
- //2. купим
- budget -= productPrice;
- totalPrice += productPrice;
- //3. достатъчен ли е бюджета
- if (budget < 0)
- {
- Console.WriteLine("You don't have enough money!");
- Console.WriteLine($"You need {Math.Abs(budget):F2} leva!");
- break;
- }
- productName = Console.ReadLine();
- }
- if (productName == "Stop")
- {
- Console.WriteLine($"You bought {countBoughtProducts} products for {totalPrice:F2} leva.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement