Advertisement
kaloyanTry

GamingStore

Sep 23rd, 2020
1,512
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.29 KB | None | 0 0
  1. using System;
  2.  
  3. namespace GamingStore
  4. {
  5.     class GameStore
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double inputBalance = double.Parse(Console.ReadLine());
  10.             string command = Console.ReadLine();
  11.  
  12.             double gamePrice = 0;
  13.             double currentBalance = inputBalance;
  14.  
  15.             while (command != "Game Time")
  16.             {
  17.                 switch (command)
  18.                 {
  19.                     case "OutFall 4":
  20.                         gamePrice = 39.99;
  21.                         break;
  22.                     case "CS: OG":
  23.                         gamePrice = 15.99;
  24.                         break;
  25.                     case "Zplinter Zell":
  26.                         gamePrice = 19.99;
  27.                         break;
  28.                     case "Honored 2":
  29.                         gamePrice = 59.99;
  30.                         break;
  31.                     case "RoverWatch":
  32.                         gamePrice = 29.99;
  33.                         break;
  34.                     case "RoverWatch Origins Edition":
  35.                         gamePrice = 39.99;
  36.                         break;
  37.                     default:
  38.                         Console.WriteLine("Not Found");
  39.                         command = Console.ReadLine();
  40.                         continue;
  41.                 }
  42.                 if (gamePrice > currentBalance)
  43.                 {
  44.                     Console.WriteLine("Too Expensive");
  45.                     gamePrice = 0;
  46.                     command = Console.ReadLine();
  47.                     continue;
  48.                 }
  49.  
  50.                 currentBalance -= gamePrice;
  51.  
  52.                 if (currentBalance >= 0)
  53.                 {
  54.                     Console.WriteLine($"Bought {command}");
  55.                 }
  56.  
  57.                 if (currentBalance < 0)
  58.                 {
  59.                     Console.WriteLine("Out of money!");
  60.                     break;
  61.                 }
  62.                 command = Console.ReadLine();
  63.             }
  64.  
  65.             if (currentBalance > 0)
  66.             {
  67.                 Console.WriteLine($"Total spent: ${(inputBalance - currentBalance):F2}. Remaining: ${(currentBalance):F2}");
  68.             }
  69.             else
  70.             {
  71.                 Console.WriteLine("Out of money!");
  72.             }
  73.         }
  74.     }
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement