
November 15th, 2012, 03:07 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 1
Time spent in forums: 18 m 28 sec
Reputation Power: 0
|
|
|
Help needed with for loop
Hi, I have some Micro code to change ASAP that is wrote in C++ I am not that good on C++ (understatement of the year)
So I was hoping someone help.
Here is the current code
case bt_measure:
{
if(ticks<5)
return;
test_report = ts_testing;
if(param2<1)
param2=1;
for(int i=0; i<5; i++)
mV[i] = 0;
if(!BondRead(3,adc_bond_i)) return;
if((bond_range==0) && (mV[3]<(param1 * 400)))
{
BOND_FULL(true);
bond_range = 1;
return;
}
mV[3] *= param2;
for(int repeat = 0; repeat < param2; repeat++)
{
if(!BondRead(0,adc_bond_diff)) return; // Uncommented by JP 14/11/12
if(!BondRead(1,adc_bond_va)) return; // Uncommented by JP 14/11/12
if(!BondRead(2,adc_bond_vb)) return; // Uncommented by JP 14/11/12
if(!BondRead(4,adc_bond_auto)) return;
T2CLRI = 0;
}
test_state = bt_start2;
for(int i=0; i<5; i++)
mV[i] /= param2;
break;
}
Currently depending on the user input this code will execute param2 number of times then take an average before displaying to the user.
Now I need it more clever,
Say I get 5 values
0.4
2.4
2.1
2.3
I need it to group every number thats within 5% of each other and ignore all others then return the average of the 5% group
Can anyone please help
|