Hello wannabeako,
After working with the program a bit the first thing I found is you defined two "std::strings", but did not include the header file "string". This does cause a problem.
using namespace std;
. This is best not to use.
Best to avoid using "goto" statements. This can be replaced with a do/while loop.
I have not fully tested the while loop in "userlogin", but it appears to work.
In the function "time", which I have not tested yet, I do have a concern about the while loops. "while (fout)" is not the best condition for a loop like this. For the output loop the while condition of 1 or true works better than basing it on the condition of the file stream. Then inside the loop you need to let the user know what to enter to when finished.
When you open a file for input the first thing you should is check that the file stream is open. A good idea for the output file, but not as necessary because the output will create the file if it does not exist.
What I like to use is:
1 2 3 4 5 6
|
if (!fin)
{
std::cout << "\n An error message \"" << fileName << "\" did not open" << std::endl;
std::this_thread::sleep_for(std::chrono::seconds(3)); // Requires header files "chrono" and "thread"
return 1;
}
|
The variable "fileName" would be defined as a "std::string" that could be used in more than one place. Or you could just use the file name and put it in double quotes.
The second line just caused the program to pause. The only things you need to do is include the header files, as noted, and change the "3" to whatever you need. The "3" refers to the number of seconds it will pause.
The "1" in "return 1;" will let you know that there is a problem. This can be any number, other than zero, that you want. Or you could use "exit(1);" to leave the program instead of returning to "main".
For reading it is more common to use
while (std::getline(fin, line))
. This way when you try to read past end of file the condition and while loop will fail.
Thought for the future. Instead of just reading the file and displaying the results consider doing something to add the information to a vector or an array for later use.
In "main" the code is correct, but the switch should be inside the do/while loop not after it. As it is only choice "3" works. I also noticed the the switch has four case statements, but the menu options only have three.
Hope that helps,
Andy