community! How's it going? The issue is that I have been thinking and researching for a while but I have not been able to find the solution, the situation is as follows:
for (int i = 0; i < getPalabras().lenghth; i++) {
a = (100 / getPalabras().Length) * i;
progreso(a);
}
getPalabras()
is a function that returns an array, which contains a list of words. What I am looking to do is that within this loop a progress is registered with the function progreso()
.
For 100 words I understand that, expressed as it is, it should work. The problem is that the amount of words inside the array is very varied,
How should I calculate the variable a
?
It is not necessary to express it exclusively in C# (Language in which I am working), if the idea is understood I would greatly appreciate it. Cheers!
To calculate the percentage (of the total) that each word represents when going through your array , the C# code would be the following:
For an example of an array of 15 words, the result would be something like this: