Advertisement
valchak

Vapor Store - Dictionary

May 26th, 2017
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. namespace _2.Vapor_Store
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     public class Program
  7.     {
  8.         public static void Main()
  9.         {
  10.             var currentBalance = decimal.Parse(Console.ReadLine());
  11.  
  12.             var totalMoney = currentBalance;
  13.            
  14.             var buyingOrder = Console.ReadLine();
  15.  
  16.             var gamesDictionary = new Dictionary<string, decimal>()
  17.             {
  18.                 {"OutFall 4" , 39.99m},
  19.                 {"CS: OG" , 15.99m},
  20.                 {"Zplinter Zell" , 19.99m},
  21.                 {"Honored 2" , 59.99m},
  22.                 {"RoverWatch" , 29.99m},
  23.                 {"RoverWatch Origins Edition" , 39.99m},
  24.             };
  25.  
  26.             var isGamePresent = false;
  27.  
  28.             while (buyingOrder != "Game Time")
  29.             {
  30.  
  31.                 foreach (var game in gamesDictionary)
  32.                 {
  33.                     if (game.Key == buyingOrder)
  34.                     {
  35.                         isGamePresent = true;
  36.  
  37.                         if (currentBalance >= game.Value)
  38.                         {
  39.                             currentBalance -= game.Value;
  40.                             Console.WriteLine($"Bought {game.Key}");
  41.                         }
  42.                         else
  43.                         {
  44.                             Console.WriteLine("Too Expensive");  
  45.                         }
  46.                         if (currentBalance == 0)
  47.                         {
  48.                             Console.WriteLine("Out of money!");
  49.                             return;
  50.                         }                                            
  51.                     }                  
  52.                 }
  53.  
  54.                 if (!isGamePresent)
  55.                 {
  56.                     Console.WriteLine("Not Found");
  57.                 }
  58.  
  59.                 buyingOrder = Console.ReadLine();
  60.                 isGamePresent = false;
  61.             }
  62.  
  63.             var remainingMoney = totalMoney - currentBalance;
  64.             Console.WriteLine($"Total spent: ${remainingMoney:F2}. Remaining: ${currentBalance:F2}");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement