Advertisement
Guest User

Untitled

a guest
Sep 26th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         string[] games = { "OutFall 4", "CS: OG", "Zplinter Zell", "Honored 2", "RoverWatch", "RoverWatch Origins Edition" };
  8.         decimal[] prices = { 39.99m, 15.99m, 19.99m, 59.99m, 29.99m, 39.99m };
  9.  
  10.         decimal budget = decimal.Parse(Console.ReadLine());
  11.         string gameName = Console.ReadLine();
  12.  
  13.         decimal currentBudget = budget;
  14.         decimal price = 0;
  15.  
  16.         bool gameExistsInArray = false;
  17.  
  18.         while (gameName != "Game Time")
  19.         {
  20.             for (int i = 0; i < games.Length; i++)
  21.             {
  22.                 if (gameName == games[i])
  23.                 {
  24.                     price = prices[i];
  25.                     if (currentBudget >= price)
  26.                     {
  27.                         Console.WriteLine($"Bought {games[i]}");
  28.                         currentBudget -= prices[i];
  29.                     }
  30.                     else
  31.                     {
  32.                         Console.WriteLine("Too Expensive");
  33.                     }
  34.                     gameExistsInArray = true;
  35.  
  36.                 }
  37.                 else if (i == games.Length - 1 && !gameExistsInArray)
  38.                 {
  39.                     Console.WriteLine("Not Found");
  40.                 }
  41.             }
  42.             gameName = Console.ReadLine();
  43.         }
  44.         if (currentBudget == 0)
  45.         {
  46.             Console.WriteLine("Out of money!");
  47.             return;
  48.         }
  49.         Console.WriteLine($"Total spent: ${budget - currentBudget:F2}. Remaining: ${currentBudget:F2}");
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement