15,665,942 members
See more:
what my weighted average grade if i have grades in three subject respectively 67,54,98 with weight of respectively 32,12,45. i know the formula =(67*32)+(54*12)+(98*45)/(32+12+45) but i dont know how its work if i use for loop.
Posted
Rajesh Anuhya 26-Feb-13 0:02am
Question Not Clear??
--RA
Sergey Alexandrovich Kryukov 26-Feb-13 0:10am
This is not a formula, this is a numeric example. If you have not idea of elementary algebra (you don't need to know any formulas, but understanding), you have nothing to do in programming.
—SA

## Solution 1

Solution A,

you can use two arrays. One for the numbers one for the corresponding weights.

C#
```public double[] _number = new double[] {67,54,98};
public double[] _weights = new double[] {32,12,45};

then:

double _wavg = 0;

for(int i = 0; i < _number.Count(); i++)
{
_wavg += ((_number[i] * _weight[i]) / (_weights.Sum())

}```

Solution B,

You can use a predefined class to store your numbers end weights

C#
```public class WeightedNumber
{
public double Number {get; set; }
public double Weight{get; set; }

}

List<wightednumber> _numbers;</wightednumber>```

The rest looks more or less the same