Advertisement
Radost09

Gaming Store

Jan 16th, 2022
1,152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P03_Gaming_Store
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             double balance = double.Parse(Console.ReadLine());
  10.             double spend = 0;
  11.  
  12.  
  13.             while (true)
  14.             {
  15.                 string command = Console.ReadLine();
  16.                 if (command == "Game Time")
  17.                 {
  18.                     break;
  19.                 }
  20.                 double price = 0;
  21.                 switch (command)
  22.                 {
  23.                     case "OutFall 4": price = 39.99; break;
  24.                     case "CS: OG": price = 15.99; break;
  25.                     case "Zplinter Zell": price = 19.99; break;
  26.                     case "Honored 2": price = 59.99; break;
  27.                     case "RoverWatch": price = 29.99; break;
  28.                     case "RoverWatch Origins Edition": price = 39.99; break;
  29.                     default: Console.WriteLine("Not Found"); continue;
  30.                 }
  31.                 if(balance < price)
  32.                 {
  33.                     Console.WriteLine("Too Expensive");
  34.                     continue;
  35.                 }
  36.                 balance -= price;
  37.                 spend += price;
  38.                 Console.WriteLine($"Bought {command}");
  39.  
  40.                 if (balance == 0)
  41.                 {
  42.                     Console.WriteLine("Out of money!");
  43.                     return;
  44.                 }
  45.             }
  46.             Console.WriteLine($"Total spent: ${spend:f2}. Remaining: ${balance:f2}");
  47.         }
  48.     }
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement