Sorry, I am new to coding and I can’t figure this out after trying everything! I have 6 masked text boxes which the user inputs decibel values, is supposed to save them to a list, input each into a formula and output a summed decibel value, but it is simply taking the variable added as 6, which is the count of the list instead of the actual values. When I tried a foreach loop, it made it an infinite loop.
private void dBAddButton_Click(object sender, EventArgs e)
{
List<double> addDBList = new List<double>();
double final;
double added = 0;
addDBList.Add(double.Parse((dB1.Text)));
addDBList.Add(double.Parse((dB2.Text)));
addDBList.Add(double.Parse((dB3.Text)));
addDBList.Add(double.Parse((dB4.Text)));
addDBList.Add(double.Parse((dB5.Text)));
addDBList.Add(double.Parse((dB6.Text)));
for (int i = 0; i < addDBList.Count; i++)
{
added += Math.Pow(10, (i / 10));
}
final = 10 * Math.Log10(added);
totaldB.Text = final.ToString();
}
}
The formula is basically 10log[10^(first value/10)+10^(second value/10)...+10^(nth value/10)]
This is your problem.
iis the index position of the array, not the actual value. You want to use this: