0
How did u solve the Coffee Time, last task on c# course?
Here is my code. I think i cheated a little. But it worked. static void Main(string[] args) { double 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 her foreach(KeyValuePair<string, double> kvp in coffee) { double newPrice = (100-discount)/100*kvp.Value; Console.WriteLine("{0}: {1}", kvp.Key, Math.Ceiling(newPrice) );
6 Answers
+ 2
(1-discount*0.01) try like this to keep it in double
+ 2
You can try this solution‘s form:
coffee[sc] -= discount * coffee[sc] / 100;
0
instead of using ceil function... do it manually and try
0
I tried without ceiling function, but it gave me every value as 0. And all doubles were integers but didnt print as wanted.
0
foreach(KeyValuePair<string, int> entry in coffee)
{
Console.WriteLine(entry.Key +": "+(entry.Value-entry.Value*discount/100));
}
0
Jackie looks good except for the <string, int> should be a <string, double> (maybe they changed it since then)