Advertisement
Guest User

TouristShop

a guest
Apr 6th, 2020
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace TouristShop
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             double budget = double.Parse(Console.ReadLine());
  13.             int productCounter = 0;
  14.             bool enoughMoney = true;
  15.             double sumPrice = 0;
  16.             string command;
  17.             while ((command = Console.ReadLine()) != "Stop")
  18.             {
  19.                 string productName = command;
  20.                 double priceProduct = double.Parse(Console.ReadLine());
  21.                 productCounter++;
  22.                 if (productCounter % 3 == 0)
  23.                 {
  24.                     priceProduct /= 2;
  25.                 }
  26.                 if (budget >= priceProduct)
  27.                 {
  28.                     budget -= priceProduct;
  29.                     sumPrice += priceProduct;
  30.                 }
  31.                 else
  32.                 {
  33.                     double moneyNeeded = priceProduct - budget;
  34.                     Console.WriteLine("You don't have enough money!");
  35.                     Console.WriteLine($"You need {moneyNeeded:f2} leva!");
  36.                     enoughMoney = false;
  37.                     break;
  38.                 }
  39.             }
  40.             if (enoughMoney)
  41.             {
  42.                 Console.WriteLine($"You bought {productCounter} products for {sumPrice:f2} leva.");
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement