I have difficulties in writting a code for adding counter -for this reading voltage every hour and find average voltage value based on the number of hour that user key in.
Let's say, user key-in "10" in the number of hour then, we will read voltage for 10 hours and find the average voltage value for 10 hours.
Let's say I use "time"=3600 in counting (such as if (time==3600)). When "time" reach to 3600secs, then it will read voltage. So we get the voltage reading for one hour.
If for "100" hours or "90hours" or whatever more than 10hours, then I have to use 3600*100 = 360,000 secs.
If for "1000" hours, I have to use 3600*1000= 3,600,000 secs, which is very large integer count.
To avoid the large integer count, is there any other ways to add "counter" for reading data for large number of hours (such as read data for 1000 hours).
Can I use two variables for counter? Please correct me if I am wrong.
I have another concern, on how to equal "n" with the number of hours that user will key in, if user keyin, 30 hours then, "n" must be 30,
[/CODE]
Code:
int tmp,time, n;
//declare time for counting, //
//n to equal with number of hours that user keyin, //
//tmp for adding values in Volt array //
typedefstructVolt
{
doubleVoltageA[1000];// to store Voltage-A reading for 1000 hours//
}Volt;
VoltVolt_sum,Volt_avg;// create two variable for finding average and total sum value for all the voltage-A reading keep in the array "Volt"
time++;//time will increase //
if(time==3600&& n==1000)// this is the part where i find difficulties, when user enter 1000 hours then, time count will be 3,600,000 secs, which is large integer count. //
{
Volt_sum[i]+=tmp;// summation of Voltage A value-reading will store inside using "tmp" variable
}
Volt_avg[i]=Volt_sum[i]/1000;// find average Voltage value for 1000 hours