Advertisement
Daniel_007

06. Christmas Decoration

Oct 26th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp3
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int budget = int.Parse(Console.ReadLine());
  10.             string product = "";
  11.             int productPrice = 0;
  12.             while (true)
  13.             {
  14.                 product = Console.ReadLine();
  15.                 if (product == "Stop")
  16.                 {
  17.                     Console.WriteLine($"Money left: {budget}");
  18.                     return;
  19.                 }
  20.                 for (int i = 0; i < product.Length; i++)
  21.                 {
  22.                     char letter = product[i];
  23.                     productPrice+= letter;
  24.  
  25.                 }
  26.                 if (productPrice<=budget)
  27.                 {
  28.                     Console.WriteLine("Item successfully purchased!");
  29.                     budget = budget - productPrice;
  30.                 }
  31.                 else
  32.                 {
  33.                     Console.WriteLine("Not enough money!");
  34.                     return;
  35.                 }
  36.                 productPrice = 0;
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement