Advertisement
fumanbest

Christmas Decoration

Dec 24th, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 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 ChristmasDecoration
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int budget = int.Parse(Console.ReadLine());
  14.             string name = Console.ReadLine();
  15.             int count = 0;
  16.             while(name != "Stop")
  17.             {
  18.                 foreach(char i in name)
  19.                 {
  20.                     count += i;
  21.                 }
  22.                 if (budget >= count)
  23.                 {
  24.                     budget -= count;
  25.                     Console.WriteLine($"Item successfully purchased!");
  26.                     count = 0;
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.WriteLine("Not enough money!");
  31.                     return;
  32.                 }
  33.                 name = Console.ReadLine();
  34.             }
  35.             if(name == "Stop")
  36.             {
  37.                 Console.WriteLine($"Money left: {budget}");
  38.             }
  39.            
  40.         }  
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement