Advertisement
Valantina

TouristShop/Exam

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