I was wondering if it is possible to do a sum of vectors with a range.
The bold is where I am concerned about the syntax. Thanks.
Code:
//Running Mean for 3 points with even weights
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
int main ()
{
float numberofterms;
cout<<"Enter the number of terms you want: " <<endl;
cin>>numberofterms;
vector<float> temperature(numberofterms); //Define a vector of 5 floats
int vectorlength;
vector<float> movingavg;
int index; //Loop counter
float average;
for (index==0; index<numberofterms; index++)
{
cout<<"Enter temperature you want to input in Celsius"<<(index+1);
cout<<": ";
cin>>temperature[index];
if (index==0)
{ movingavg[index]=temperature[index];
cout<<"Temperature [1]= "<<temperature[0]<<" C"<<endl;
continue;
}
else if (index==numberofterms-1)
{
movingavg[index]=temperature[index];
cout<<"Temperature ["<<numberofterms<<"]= "<<temperature[numberofterms-1]<<" C"<<endl;
continue;
}
average= sum((temperature[index-1:index+1]/3));
movingavg[index]=average;
cout<<"Temperature ["<<index+1<<"] = "<<average<<" C"<<endl;
cout<<"The original temperature ["<< index+1<<"]"<<temperature[index]<<"] C has been replaced." <<endl;
}
system ("PAUSE");
return 0;
}