Advertisement
silvana1303

tourist shop

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