private List games = new List(); private double totalPrice = 0.0; private struct Game { public int gameId; public string platform; public string rating; public string type; public int quantity; public double price; public string title; public int quantityInCart; } private void buttonAddToCart_Click(object sender, EventArgs e) { if (listBoxGames.SelectedItem == null) return; string selectedItem = listBoxGames.SelectedItem.ToString(); int gameId = int.Parse(selectedItem.Split(' ')[0]); for (int i = 0; i != games.Count; i++) { Game game = games[i]; if (game.gameId == gameId) { Console.WriteLine($"{game.quantity} - {game.quantityInCart}"); if (game.quantity - game.quantityInCart == 0) { MessageBox.Show($"This item has a quantity of {game.quantity} and you currently have {game.quantityInCart} in your cart!", "Out of stock", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } listBoxCart.Items.Add($"{game.gameId} - {game.title}"); textBoxTotalPrice.Text = (totalPrice += game.price).ToString("C"); game.quantityInCart++; return; } } }