troubleshooting Question

user input file

Avatar of ldken
ldken asked on
Programming Languages-OtherC++
5 Comments1 Solution488 ViewsLast Modified:
Hi Experts,
Same computer class program, different problem... the program requires the user to provide either the input data file name or 'E' / 'e' to exit program. So far it will read and process the input string to exit but my problems is that if the input is a data file name it also goes into the  if ( userInFile == "E " || "e ") then just follows the same exit routine as if it were and E / e.
Here is how I have it coded.  Any suggestions will be greatly appreciated. ldken

void beginProgProcess(ifstream& inData, bool& yesEndProgram)
{
    bool isValid = true; // true = input selection ok, end loop
    string userInFile;

    while (isValid)
    {
        cout << endl << " Input datafile Name ... or 'E' to exit program ";
        getline(cin, userInFile);

        cout << " after cin input is " << userInFile << endl;
        system("pause");//------------------------------------------------------>prog check

        // user input to exit program
        if (userInFile == "E " || "e ")
        {
            cout << " after userInFile == E is " << userInFile << endl;
            system("pause");//-------------------------------------------------->prog check

            yesEndProgram = true;
            isValid = false;
        } // end if.

        // attempt to open user supplied data file name.
        else
        {
            cout << " just after else to open inData " << endl;
            system ("pause");//------------------------------------------------->prog check

            yesEndProgram = false; // do not end program as a file is provided.

            inData.open(userInFile.c_str());

            //test and warning message if open file does not exist.
            if(!inData)     // if file does not exist, clear, stmt to user, loop
            {
                inData.clear();

                cout << endl << "This Input file " << userInFile;
                cout << " does not exist. Try Again" << endl << endl;

                yesEndProgram = true;

                isValid = false;
            } // end if
            isValid = true;
        } //end else
    } // end while
}
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros