Професионална програма
Loading...
+ Нов въпрос
Axiomatik avatar Axiomatik 1054 Точки

Code was almost complete, just some break-conditions had to be modified and budget/balance had to be modified only when a game was successfully bought.

Best,

using System;

namespace Gaming_Store
{
    class Program
    {
        static void Main(string[] args)
        {
            double budget = double.Parse(Console.ReadLine());
            string input = Console.ReadLine();

            double price = 0;
            double balance = 0;

            while (input != "Game Time")
            {
                string gameName = input;

                switch (gameName)
                {
                    case "OutFall 4":
                        price = 39.99;
                        break;
                    case "CS: OG":
                        price = 15.99;
                        break;
                    case "Zplinter Zell":
                        price = 19.99;
                        break;
                    case "Honored 2":
                        price = 59.99;
                        break;
                    case "RoverWatch":
                        price = 29.99;
                        break;
                    case "RoverWatch Origins Edition":
                        price = 39.99;
                        break;
                    default:
                        Console.WriteLine("Not Found");
                        input = Console.ReadLine();
                        continue;
                        //break;
                }

                //balance += price;
                //budget -= balance;


                if (budget != 0)
                {
                    if (budget < price)
                    {
                        Console.WriteLine($"Too Expensive");
                    }
                    else
                    {
                        balance += price;
                        budget -= price;

                        Console.WriteLine($"Bought {gameName}");
                        //Console.WriteLine($"Total spent: ${balance}. Remaining: ${budget:f2}");
                    }
                }

                if (budget == 0)
                {
                    Console.WriteLine($"Out of money");
                    break;
                }

                //gameName = Console.ReadLine();
                input = Console.ReadLine();
            }

            if (input == "Game Time")
            {
                Console.WriteLine($"Total spent: ${balance}. Remaining: ${budget:f2}");
            }
        }
    }
}

 

0