Hello Cplusstudent01,
I do not know why I missed this on, but happened to find it if yo still need help,
Line 9 I would put above main as
const unsigned int ARRAYSIZE{9};
. Because on lines 13 - 15 what is between the [] needs to be a constant like 9 or a variable defined as a constant. This way if you need to make a change it is only in one place.
Line 14. Defines a 2D array yet the function expects a 1D array. The other thing I would do is make line 14 a "std::string" and not a char array. You will find the string is much easier to use.
On line 41 for the condition it is best not to loop on "eof".
while(!inFile.eof())
I do not know why people teach this. This is a bad idea as it does not work the way you think it will. Generally by the time the while condition determines that "eof" has been reached you will have processed the last read twice and wondering why it shows up twice.
What happens is the while condition is checked and “eof” has not been set yet. After entering the while loop you read the last line or bit of information from the file process the information reach the bottom of the while loop. At this point “eof” has not been set yet and you return to the while condition which is still good. After entering the loop you try to read from the file, but now there is nothing left to read and “eof” is set, but you do nothing at this point to deal with the “eof” condition. So you process what information is in the variables from the last read before returning to the while condition where it finally detects the “eof”, but you have processed the last good read twice unless you have cleared the variables at the end of the while loop in which case the last process will be blank.
A more acceptable way of using the while loop is:
1 2 3 4 5
|
while (infile >> someVariable)
{
infile >> additionalVariables;
// Additional code.
}
|
In the above example you can set up the while condition to read one variable, two or more variables or use “std::getline(?, str)” where ? could be from “std::cin” or from a file stream and “str” represents any “std::string” variable.
inside the while loop you will need to read into all three variables and I would change the input for description to a "std::getline(...)"
The second while loop has more potential except that you are missing the {}s for the while block.
If you put the two while loops together you will have something.
Hope that helps,
Andy
P.S. If this gets archived you may have to start a new message in April.