+ 5

Coffee Time - C# The Last Excerise

https://www.sololearn.com/coach/1054?ref=app I have attempted this but I can't figure out how to work out the discount of the <int> value in the dictionary "coffee" and how to output this.

26th Dec 2020, 10:12 AM
aka :)
aka :) - avatar
33 Antworten
+ 48
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { 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); //your code goes here foreach (KeyValuePair<string, int> entry in coffee) { Console.WriteLine(entry.Key + ": " + (entry.Value - entry.Value * discount / 100)); } } } }
7th Feb 2021, 4:46 PM
Md Momin Uddin Hridoy
Md Momin Uddin Hridoy - avatar
+ 12
Yes, I updated my code and now it passes the unit tests. Thanks XXX MrDevEzeoke for the support. Anyway I think the scenario given in that exercise should have been little bit more clearer.
26th Dec 2020, 10:45 AM
Tharinda Nimnajith
Tharinda Nimnajith - avatar
26th Dec 2020, 10:35 AM
Tharinda Nimnajith
Tharinda Nimnajith - avatar
+ 4
I also have a problem with the exercise. I added the code I wrote for the exercise but unit tests fail. I don't get how the discount works there.
26th Dec 2020, 10:37 AM
Tharinda Nimnajith
Tharinda Nimnajith - avatar
+ 3
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { 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); //your code goes here foreach (var s in coffee.Keys.ToArray()) { coffee[s] = coffee[s] - coffee[s] * discount/100; Console.WriteLine(s + ": "+ coffee[s]); } } } } That´s a possible way to solve this problem using coffee.Keys.ToArray() in the foreach loop for those who asked:)
12th Dec 2022, 10:19 AM
Tom Klotz
+ 3
try this code its work using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; 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 foreach(KeyValuePair<string,double>entry in coffee) { Console.WriteLine(entry.Key+": " +(entry.Value - entry.Value * discount/100)); } } } }
10th Sep 2023, 10:01 AM
Gaurav Dandade
Gaurav Dandade - avatar
+ 2
has anyone solved the Drawing Application Challenge in Inheritance and polymorphism
7th Jan 2021, 9:05 AM
Raymond Van den Broek
Raymond Van den Broek - avatar
+ 2
Just wondering why nobody has used the coffee.Keys.ToArray() in their solutions?
18th Jun 2021, 1:53 PM
Ritchie Robinson
Ritchie Robinson - avatar
+ 2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { 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); //your code goes here foreach(string s in coffee.Keys.ToArray()){ Console.WriteLine(s+": {0}",coffee[s]-coffee[s]*discount/100); } } } }
18th Aug 2022, 11:01 AM
Mohamed Ouhadda
Mohamed Ouhadda - avatar
+ 1
Oh. Thank you man.
26th Dec 2020, 10:37 AM
aka :)
aka :) - avatar
+ 1
Tharinda Nimnajith the input represents discount percentage, not the discount itself.
26th Dec 2020, 10:39 AM
XXX
XXX - avatar
+ 1
~DevEzeoke16[BTS]~ Thanks a lot for this answer! My answer was correct in 95% of the cases, which was really bugging me ^^
23rd Apr 2021, 8:26 PM
Ewout Lagendijk
Ewout Lagendijk - avatar
+ 1
Why do we use coffee.Keys.ToArray() instead of coffee.keys ????
8th Oct 2022, 5:41 PM
Mr Ajiero
Mr Ajiero - avatar
0
MrDevEzeoke Read the question again. It says that a discount value is given as input and you have to output the price of each coffee type AFTER APPLYING THE DISCOUNT. So for example, if the input is 10, you will apply 10% discount on each coffee type. In the end the cost of Americano = 50 - 10% of 50 = 45 and so on
26th Dec 2020, 10:38 AM
XXX
XXX - avatar
0
Tharinda Nimnajith yeah what XXX said I just realised but thank you for the answer as it will help me perform the new value.
26th Dec 2020, 10:40 AM
aka :)
aka :) - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { 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(var c in coffee) Console.WriteLine(
quot;{c.Key}: {c.Value-c.Value*discount/100}"); } } }
23rd Feb 2021, 1:46 AM
Mohamed BOUANANE
Mohamed BOUANANE - avatar
0
Ewout Lagendijk Your welcome mate.
1st May 2021, 7:28 AM
aka :)
aka :) - avatar
0
@Richie Ro binson Im wondering aswell. I didn't use coffee.Keys.ToArray() either. using System; using System.Collections.Generic; using System.Linq; namespace Coffee_Time { 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", 30); coffee.Add("Cappucino", 90); coffee.Add("Mocha", 100); foreach (KeyValuePair<string, int>d in coffee) { int zahl = d.Value * discount / 100; Console.WriteLine(
quot;{d.Key}: {d.Value - zahl} "); } } } }
21st Jun 2021, 4:21 PM
David
David - avatar
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace sololearn { 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); String[] coffeename = coffee.Keys.ToArray(); foreach (string key in coffeename) { Console.WriteLine("{0} : {1}", key, Math.Round(coffee[key] * (Convert.ToDouble(100 - discount) / 100), MidpointRounding.AwayFromZero)); } } }
6th Jul 2021, 12:52 AM
Than Hoang Loc
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { 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); //your code goes here foreach (KeyValuePair<string, int> entry in coffee) { Console.WriteLine(entry.Key + ": " + (entry.Value - entry.Value * discount / 100)); } } } }
9th Sep 2021, 11:59 PM
Mahdi Tahir Ahmat
Mahdi Tahir Ahmat - avatar