Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace GamingStore
- {
- class Program
- {
- static void Main(string[] args)
- {
- double budget = double.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- double spent = 0;
- while (true)
- {
- bool isFound = true;
- double price = 0;
- if (budget == 0)
- {
- Console.WriteLine("Out of money!");
- break;
- }
- else if (command == "Game Time")
- {
- Console.WriteLine($"Total spent: ${spent:F2}. Remaining: ${budget:F2}");
- break;
- }
- else
- {
- switch (command)
- {
- case "OutFall 4":
- price = 39.99;
- break;
- case "CS: OG":
- price = 15.99;
- break;
- case "Zplinter Zell":
- price = 19.99;
- break;
- case "Honored 2":
- price = 59.99;
- break;
- case "RoverWatch":
- price = 29.99;
- break;
- case "RoverWatch Origins Edition":
- price = 39.99;
- break;
- default:
- Console.WriteLine("Not Found");
- isFound = false;
- break;
- }
- if (isFound)
- {
- if (budget >= price)
- {
- Console.WriteLine($"Bought {command}");
- budget -= price;
- spent += price;
- }
- else
- {
- Console.WriteLine("Too Expensive");
- }
- }
- command = Console.ReadLine();
- }
- }
- }
- }
- }
- Решение с речник:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace GamingStore
- {
- class Program
- {
- static void Main(string[] args)
- {
- double balance = double.Parse(Console.ReadLine());
- Dictionary<string, double> games = new Dictionary<string, double>{
- { "OutFall 4", 39.99},
- { "CS: OG", 15.99},
- { "Zplinter Zell", 19.99 },
- { "Honored 2", 59.99 },
- { "RoverWatch", 29.99 },
- { "RoverWatch Origins Edition", 39.99 }
- };
- string command = Console.ReadLine();
- double sum = 0;
- while (command != "Game Time" && balance != sum)
- {
- if (games.ContainsKey(command))
- {
- if (games[command] <= (balance - sum))
- {
- sum += games[command];
- Console.WriteLine($"Bought {command}");
- }
- else
- {
- Console.WriteLine("Too Expensive");
- }
- }
- else
- {
- Console.WriteLine("Not Found");
- }
- command = Console.ReadLine();
- }
- if (balance == sum)
- {
- Console.WriteLine("Out of money!");
- }
- else
- {
- Console.WriteLine($"Total spent: ${sum:F2}. Remaining: ${balance - sum:F2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement