Energy per hour

closed account (3bRk92yv)
Hi I need to be able to output two columns into a file. One is for hour and one is for total energy used during that hour interval. The problem I am having is I don't know how to store the total energy per hour. This is what I have done so far and not sure where it is I am going wrong. Can someone give me some guidance please.

void byHourly(vector<double>& hours, vector<double>& powerVect, vector<double>& deltaT)
double index = 0;
double hourlyEnergy = 0;
vector <double> hourly;
double kWConversion = 0;
while( < ( + 1) || index != 24)
if( + 1) ==
hourlyEnergy = hourlyEnergy + 0.5 * (( + + 1)) *;

hourly.push_back(hourlyEnergy / kWConversion);
while( < ( + 1) || index != 24)

I believe you made a typo here as one of the conditions shall always be true.

Are you finished writing the function (as far as what it basically does)? You inserted values into hourly but hourly is never used. kwConversion also looks unused. kwConversion's value is never changed. Each push back to hourly will involve division by 0 (or a really, really, really small magnitude).

Remember to increment your index, otherwise index will forever be 0.

Random Note:
-Passing references to mutable objects suggests that you're going to modify them in some way. However, the function you wrote treats the parameters as constant. Therefore, I suggest you write this:
const vector<double>& hours, //etc. 

-Since you are using vectors, I strongly recommend you take advantage of its ability to tell you its size.
index != hours.size()
Last edited on
Topic archived. No new replies allowed.