Trying to loop within a loop

I've been at this code for two days now and still cant seem to crack it. We've been given a txt file with the voltage and current which a household uses in
Last edited on
Have you at least tried to make it? Show us what you got, then we can help.
ofstream outFile;
outFile.open("byhour.txt");

int t;

}
Last edited on
Please use our code tags, they exist for a reason. Anyway, i think you did right.

You get the time in the file, convert to seconds, then get the difference in seconds between them. After that, you divide by 3600, which will give you the hours.

I'm not going to do the code, but here is few tips to make you think about how to do it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>

/*
This code prints the proportions between month,day and hour relative to 4 hours.
Also, a example of what you should do.
*/

int main()
{
    double seconds = 4 * 3600;
    std::cout << "Month:" << seconds/((3600 * 24) * 30) << std::endl;
    std::cout << "Days:" << seconds/(3600 * 24) << std::endl;
    std::cout << "Hours:" << seconds/3600 << std::endl;
    std::cout << "Seconds" << seconds  << std::endl;


// Example code.
    int power = 10; // random number for KwH.
    int initial_time = 1;// random time(let's say it is from the file.)
    // Below we convert "initial_time" to seconds, then do the function.
    // energy = power*time
    std::cout << "Energy spent between 1:00 ~ 4:00 am:" << power  * ((seconds - (initial_time * 3600))/3600);
    std::cout << "KwH" << std::endl;
}
Last edited on
Thanks for the effort, I see what you're saying. Its almost what I need except that still don't know how to get the summation of the power between the hourly intervals? And how would I store them so I can later write them to a text file?


Look at the example code at line 22. If you test the above code it will print what you said. But, as it is an example it contains non-relative values.

Also, if you don't know how to store values, i recommend you to go few steps back and look at the basics.

http://www.cplusplus.com/doc/tutorial/variables/
http://www.cplusplus.com/doc/tutorial/operators/
http://www.cplusplus.com/doc/tutorial/files/

I saw that but im given about 55000 lines of data, each line containing voltage and current and each line varies roughly 0.5 seconds(cant be assumed).

How would I be able to tally up the power from the first second the data enters until 59:59. and then start from zero again into the next hour?
Can you eleborate better your last sentence? because i didn't understand what you mean. Also, provide your full code in proper format.
Topic archived. No new replies allowed.