Hatte der Aufgabensteller einen Fehler gemacht oder bin ich doof?
Aufgabe:
A coffee shop manager is running a promotion and wants to offer a discount for coffee drinks.
The program you are given takes the discount value as input and defines a dictionary, where the names of the coffee drinks are set as keys, and their prices are set as values.
Write a program to discount all of the prices and output a new price list in the format shown below.
Und zusätzlich als Anweisung steht dort:
Use
coffee.Keys.ToArray() inside the foreach loop.
Note the
space after the ":" in the output.
In dem vorgegebenen Code wird ein Dictionary verwendet. Wie soll ich die Aufgabe nun also lösen, wenn es kein "Keys.ToArray" in Dictionaries gibt?
namespace SoloLearn
{
class Program
{
static void Main(string[] args)
{
int discount = Convert.ToInt32(Console.ReadLine());
Dictionary<string, double> coffee = new Dictionary<string, double>();
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);
// your code goes here
}
}
}