0

Can anyone help me with this? Unable to display the output they asked for as the discount amount is different for different type

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. Sample Input 10 Sample Output Americano: 45 Latte: 63 Flat White: 54 Espresso: 54 Cappuccino: 72 Mocha: 81 Hint : Use coffee.Keys.ToArray() inside the foreach loop. Note the space after the ":" in the output. ////////////////////////////// My code : 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 (string s in coffee.Keys.ToArray()) Console.WriteLine(s + ": " + Convert.ToInt32(coffee[s]-discount)); } } }

10th Nov 2021, 9:47 PM
Rubayet Kamal
Rubayet Kamal - avatar
2 ответов
+ 5
Mathe hint: New price = list price - list price * discount / 100
10th Nov 2021, 10:04 PM
JaScript
JaScript - avatar
+ 1
JaScript Thanks a lot man. I completely forgot that the discount is the percentage. I thought that the input amount will be deducted from every value. And so I was so confused when I saw the values they are asking for. Again man,Thanks a lot.
10th Nov 2021, 10:13 PM
Rubayet Kamal
Rubayet Kamal - avatar