[Solved] Getting average values from one Array to another Array [closed]


Maybe something like this could work… Did this on my mac in sublime text so you’ll still have to work with. Should get the point though.

 public class Foo 
 {
    List<int> main = new List<int>(100);
    List<int> rollingAverages = new List<int>(100);

    public void Add(int score)
    {
        main.Add(score);
        if(main.Count > 10)
        {
            int rollingAverage = AverageLast10();
            rollingAverages.Add(rollingAverage);
        }
    }

    public int AverageLast10()
    {
        int sum = 0;
        for(int i = main.Count - 10; i < 10; i++)
        {
            sum += main[i];
        }
        return sum / 10;
    }
 }   


Somewhere else in the code

Foo foo = new Foo();
foo.Add(94);
foo.Add(94);
...
 yadda yadda yadda

1

solved Getting average values from one Array to another Array [closed]