Can anyone assist in checking my code Please- Counters

I would appreciate a lot if anyone please just confirm that my code does as the example says: This is just part of a code so not to worry much about before or other things but mainly where it says //Apply the filter to the data

// Example of what it is supposed to do
// before filtering:
// data_in = [0 1 3 6 3 1 0]
// filter = [-0.5 1 -0.5]
// after filtering:
// data_out = [-0.5 -0.5 3 -0.5 -0.5]
// where
// data_out[0]=data_in[0]*filter[0]+data_in[1]*filter[1]+data_in[2]*filter[2]
// data_out[1]=data_in[1]*filter[0]+data_in[2]*filter[1]+data_in[3]*filter[2]
// data_out[2]=data_in[2]*filter[0]+data_in[3]*filter[1]+data_in[4]*filter[2]
// data_out[3]=data_in[3]*filter[0]+data_in[4]*filter[1]+data_in[5]*filter[2]
// data_out[4]=data_in[4]*filter[0]+data_in[5]*filter[1]+data_in[6]*filter[2]



the actual code is :
// initialize the data structure that holds the filtered data
delete [] DataOut.values;
DataOut.Length = Datain.Length - Filter.Length + 1;

// get memory for the filtered data
DataOut.Values = new double [DataOut.Length];
if (DataOut.Values == 0
{
cout << " insufficient memory for allocation!!" << endl;
exit(1);
}
// apply the filter to the data
for (unsigned long CountData = 0; CountData < DataOut.Length; CountData++)
{
DataOut.Values[CountData] = 0.0;
for (Unsigned long Count_Filter = 0; Count_Filter<Filter.Length;Count_Filter++)
{
DataOut.Values[CountData] += DataIn.Values[CountData+Count_Filter] * Filter.Values[Count_Filter];
}
}

[code] Your code goes here [/code]
The language(?) is case sensitive Unsigned unsigned long
It seems correct, but try to avoid reinventing the wheel http://www.cplusplus.com/reference/std/numeric/inner_product/

You better encapsulate the allocation
Topic archived. No new replies allowed.