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;
- namespace TouristShop
- {
- class Program
- {
- static void Main(string[] args)
- {
- double budget = double.Parse(Console.ReadLine());
- int productCounter = 0;
- bool enoughMoney = true;
- double sumPrice = 0;
- string command;
- while ((command = Console.ReadLine()) != "Stop")
- {
- string productName = command;
- double priceProduct = double.Parse(Console.ReadLine());
- productCounter++;
- if (productCounter % 3 == 0)
- {
- priceProduct /= 2;
- }
- if (budget >= priceProduct)
- {
- budget -= priceProduct;
- sumPrice += priceProduct;
- }
- else
- {
- double moneyNeeded = priceProduct - budget;
- Console.WriteLine("You don't have enough money!");
- Console.WriteLine($"You need {moneyNeeded:f2} leva!");
- enoughMoney = false;
- break;
- }
- }
- if (enoughMoney)
- {
- Console.WriteLine($"You bought {productCounter} products for {sumPrice:f2} leva.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement