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) );

13th Feb 2021, 9:15 AM
Miika Viinikainen
Miika Viinikainen - avatar
6 Respuestas
+ 2
(1-discount*0.01) try like this to keep it in double
13th Feb 2021, 9:46 AM
NaSaPaKri
NaSaPaKri - avatar
+ 2
You can try this solution‘s form: coffee[sc] -= discount * coffee[sc] / 100;
13th Feb 2021, 10:17 AM
JaScript
JaScript - avatar
0
instead of using ceil function... do it manually and try
13th Feb 2021, 9:39 AM
NaSaPaKri
NaSaPaKri - avatar
0
I tried without ceiling function, but it gave me every value as 0. And all doubles were integers but didnt print as wanted.
13th Feb 2021, 9:42 AM
Miika Viinikainen
Miika Viinikainen - avatar
0
foreach(KeyValuePair<string, int> entry in coffee) { Console.WriteLine(entry.Key +": "+(entry.Value-entry.Value*discount/100)); }
6th Mar 2022, 9:17 PM
Jackie
Jackie - avatar
0
Jackie looks good except for the <string, int> should be a <string, double> (maybe they changed it since then)
17th Apr 2023, 3:35 PM
Avery Finchum
Avery Finchum - avatar