Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ConsoleApp3
- {
- class Program
- {
- static void Main(string[] args)
- {
- int budget = int.Parse(Console.ReadLine());
- string product = "";
- int productPrice = 0;
- while (true)
- {
- product = Console.ReadLine();
- if (product == "Stop")
- {
- Console.WriteLine($"Money left: {budget}");
- return;
- }
- for (int i = 0; i < product.Length; i++)
- {
- char letter = product[i];
- productPrice+= letter;
- }
- if (productPrice<=budget)
- {
- Console.WriteLine("Item successfully purchased!");
- budget = budget - productPrice;
- }
- else
- {
- Console.WriteLine("Not enough money!");
- return;
- }
- productPrice = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement