Hello nhantrivo,
When I run your program I get this:
Welcome to the great Grade Calculator!
Please enter the file you wish to open:
|
Now I have 2 problems:
1. At this point I have no idea what file(s) are available to open.
2. I have no input file to use or any idea what to put into it.
You need to provide the input file. If it is a large file then a good sample will do.
Not knowing what the input file looks like lines 21 - 34 make no sense.
Even if line 38 would be true the loop condition would loop 1 more time than you need to because you would set "eof" after you check for "eof".
while (file >> gradeCategory)
would be the best way to read a file of unknown length, but even that may not work depending on the input file.
You really need to post the input file so everyone can see what you are working with.
On lines 8 and 41 you do not have to initialize a "std::string". It is empty when defined and has no size.
On line 15 using "std::getline()" would be a better choice in case the file name has a space.
Be careful with
file.is_open()
. Just because the file is open may not mean the file is usable.
Line 26 uses the variable "fileName". This will over write the original file name you entered on line 15, so if you would need that later you no longer have it.
I offer this as a suggestion:
1 2 3 4 5 6 7 8 9 10 11
|
const std::string inFileName{ "" }; // <--- Put File name here.
std::ifstream inFile(inFileName);
if (!inFile)
{
std::cout << "\n File " << std::quoted(inFileName) < " did not open.\n";
//std::cout << "\n File \"" << inFileName << "\" did not open.\n";
return 1;
}
|
If there is a problem you leave the program because there is no point in continuing. The "!inFile" check for more than just being open.
For line in your case
std::string inFileName;
to let the user enter a name.
That is what I see for the moment. I will let you know if I find more.
Andy