Hello SammyB,
Looking over the program I noticed some problems.
In the subject line you say
in text file array
. Are you considering the text file an array? Or do you want to store the numbers form the input file into an array?
It may be some extra work, but I would consider reading the txt file into an array in the program. This would come in handy should you add to the program. If not the sum of all the numbers read can be sotred for later use in calculating the average.
In the class you define an "ifstream" for "inRain" and then again in main. The one in main is redundant, not used and not needed.
In the function "testFile()" you should find this code of more use:
1 2 3 4 5 6
|
if (!inRain)
{
cerr << "Input file did not open properly" << endl;
std::this_thread::sleep_for(std::chrono::seconds(5)); // Requires header files "chrono" and "thread"
exit(1);
}
|
If you use VS as I do and run the program from the IDE you should find that the console window closes when the program ends. The second line of code will keep the console window open for 5 seconds before the "exit()" ends the program and the console window closes giving the user time to read the message.
"exit(1234);" is OK, but over kill. Any number greater then zero is considered an error exit. So all you really need is "1" or "2" or "3" etc. inside the ()s. If You should have more than one "exit()" in the program the number will help to
find where the problem is.
You have referred to an input file for the month of June. Since June only has 30 days this could be a potential problem. It would also help if you post the input file, so anyone working on the program will be using the same information that you are. This way totals and the average should math.
Hope that helps,
Andy