Advertisement
Guest User

04.Tourist_Shop

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