Click here for important information about

c++ file name loop

Borland Delphi 2009 professional & c++bu...
February 16, 2010 at 08:44:01
Specs: Windows 7
This is a homework assignment. For part of my assignment I have to ask the user for a file name (contains spaces) and then test to see if the file is valid if not loop it and ask the user if they want to enter in a different file name. If they don't, exit, if they do test it again to see if it is valid.

Below is my code for that part of the program. The loop created will not let the user re-enter a file name. I could use some help in figuring out how to fix it.


cout << "Please enter the file name including the file extension for this \n"
<< "years rainfall: ";
getline(cin, ActFileName); //get file name;

while( //test file
// if file failed ask the user if they want to try again
cout << "File name is invalid. Would you like to enter another file name?
<< 'y' or 'n' \n";
cin >> yn;

if (yn == 'y')
//If user wants to re-enter file name ask and get the new file name
cout << "Plese re-enter the file name for this years rainfall: \n";
getline(cin, ActFileName);;
else //if user says no, exit


See More: c++ file name loop

February 16, 2010 at 10:04:17
You really should be asking this on the Programming forum.

Report •
Related Solutions

Ask Question