0

only value of dictionary gets written into the variable

foreach(KeyValuePair<string, int> kvp in coffee) { //it ignores all operations and only writes kvp.Value into discounted discounted = kvp.Value*(1-(discount/100)); Console.WriteLine("{0}: {1}", kvp.Key, discounted); } as the comment in the foreach loop says; for some reason all arithmetic operations get completely ignored and only the value gets written into discounted. i also tried first writing the value only and then calculate the discounted price, but this still did nothing. also tried Convert.ToInt32 on the value... still nothing. so what am i missing?

3rd Sep 2021, 2:07 PM
Wolfgang
2 ответов
+ 1
What is <discount>? If it is an integer, and it is less than 100, then dividing <discount> with 100 will give you a zero, because integer division doesn't care about fractional parts. That is probably why 1 - ( discount / 100 ) has no effect. You pretty much were doing 1 - 0 there ...
3rd Sep 2021, 2:25 PM
Ipang
+ 2
Can I see all your code
4th Sep 2021, 8:12 AM
Code Land
Code Land - avatar