0
votes

I was trying to finish some coding challenge where I have to update a menu when the program runs where a user enters a discount amount applied to all the prices.

using System;
using System.Collections.Generic;

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 x in coffee.Keys)
        {
            coffee[x]-=coffee[x]*(discount/100)
        }

I cannot change the prices with any iteration I tried. Help!

Please include the error in your question (as text).DiplomacyNotWar
Does this answer your question? How can I divide two integers to get a double? You do an integer division. If discount is smaller than 100, the result is 0. Divide by 100.0 to get a floating point division.SomeBody
int discount = Convert.ToInt32(Console.ReadLine()); - unrelated: Never trust user input. Use int.TryParse.Fildor