0

I was trying to finish some coding challenge where I have to update a menu when the program runs where a user enters a discount amount applied to all the prices.

using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        int discount = Convert.ToInt32(Console.ReadLine());

        Dictionary<string, int> coffee = new Dictionary<string, int>();
        coffee.Add("Americano", 50);
        coffee.Add("Latte", 70);
        coffee.Add("Flat White", 60);
        coffee.Add("Espresso", 60);
        coffee.Add("Cappuccino", 80);
        coffee.Add("Mocha", 90);

        foreach(string x in coffee.Keys)
        {
            coffee[x]-=coffee[x]*(discount/100)
        }

I cannot change the prices with any iteration I tried. Help! It give me the next Ex: System.InvalidOperationException:

Collection was modified; enumeration operation may not execute.

0 Answers0