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
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.
#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;
}
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?