Advertisement
sanyakasarova

05. Tourist Shop

Oct 23rd, 2021
685
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Loops
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double budget = double.Parse(Console.ReadLine());
  10.  
  11.             int counter = 0;
  12.             double total = 0;
  13.  
  14.             string input = Console.ReadLine();
  15.  
  16.             while (input != "Stop")
  17.             {
  18.                 double price = double.Parse(Console.ReadLine());
  19.                 counter++;
  20.  
  21.                 if (counter % 3 == 0)
  22.                 {
  23.                     price = price / 2;
  24.                 }
  25.  
  26.                 if (price > budget)
  27.                 {
  28.                     Console.WriteLine("You don't have enough money!");
  29.                     Console.WriteLine($"You need {price - budget:f2} leva!");
  30.                     break;
  31.                 }
  32.                 else
  33.                 {
  34.                     budget -= price;
  35.                     total += price;
  36.                 }
  37.  
  38.                 input = Console.ReadLine();
  39.             }
  40.  
  41.             if (input == "Stop")
  42.             {
  43.                 Console.WriteLine($"You bought {counter} products for {total:f2} leva.");
  44.             }
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement