0
public static void Main (string[] args)
{
    int c = 100;
    double percent;

    for (int i = 0; i < c; i += 10)
    {
        percent = (i / c) * 100;
    }

Why doesn't the assignment to 'percent' work? I've been running it in debugger and it just says it's 0.

Battle
  • 786
  • 10
  • 17
  • 2
    Convert `lineIndex` to double first – thirdDeveloper Jul 10 '18 at 10:07
  • 2
    What does "doesn't work" mean? Note that `(lineIndex/lineCount)*100` performs an **integer division**, so the result will always be `0`. You need to convert `lineCount` and/or `lineIndex` to `double` before. – René Vogt Jul 10 '18 at 10:07
  • Because lineIndex/lineCount is a division of two ints and the result will also be an int. You should cast at least one of them to double. Try percent = ((double)lineIndex/lineCount)*100 – Alexandru Pupsa Jul 10 '18 at 10:08
  • All the values participating in the calculation are integer so the output you get is also integer. You have to convert at least one if the variable to double before calculation – Chetan Jul 10 '18 at 10:09
  • Ah ok, thanks everyone, I assumed it would just be a double sized value of an integer, my mistake. Thanks for the help –  Jul 10 '18 at 10:13

0 Answers0