Advertisement
skipter

C# Fundamentals - Vapor Store / Switch case

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