+ 1

Friends Corect me !

This is the end project in c# learning can you tell me i write with corect way? The my code part come from me. yes code is corect but im not sure its proper way or not can you help me? what is best way to write this code? 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); //my code foreach (string FinalPrice in coffee.Keys) Console.WriteLine(FinalPrice + ": " + (coffee[FinalPrice]-coffee[FinalPrice]*discount/100)); } } //Program asking me to implement the given // discount from user in coffee price

26th Jun 2021, 9:35 PM
Kouros pourmohseni
Kouros pourmohseni - avatar
4 Antworten
+ 2
This works. If you would like more readability so that you can distinguish between your key/value pair you could also directly access the built in properties as following: foreach(var item in coffee) Console.WriteLine(item.Key +": " + (item.Value - (item.Value * discount/100)));
29th Jun 2021, 5:23 AM
BlueFire1712
BlueFire1712 - avatar
+ 1
Kouros pourmohseni There is no other way to solve this problem. It's ok.
27th Jun 2021, 4:50 AM
A͢J
A͢J - avatar
+ 1
🅰🅹 🅐🅝🅐🅝🅣 Ok then thank you ❤
27th Jun 2021, 7:49 AM
Kouros pourmohseni
Kouros pourmohseni - avatar
0
Jamie Workman intristing ❤
29th Jun 2021, 5:55 AM
Kouros pourmohseni
Kouros pourmohseni - avatar