- #1
magnifik
- 360
- 0
i'm having trouble with user input & error checks. after the first iteration, if there is an error, the correct error message shows up. but for the next iterations, the error messages for the opening of the input and output files show along with the correct one. idk if that made any sense...
screen should look like:
e power input.txt output.txt
with an error it looks like:
a power input.txt output.txt
Command not allowed. Try again.
e p0wer input.txt output.txt
Key invalid. Try again.
Can't open file input.txt. Try again. // this should not show
Can't open file output.txt. Try again. // this should not show
screen should look like:
e power input.txt output.txt
with an error it looks like:
a power input.txt output.txt
Command not allowed. Try again.
e p0wer input.txt output.txt
Key invalid. Try again.
Can't open file input.txt. Try again. // this should not show
Can't open file output.txt. Try again. // this should not show
Code:
int main(){
char choice;
string key;
char inputFile[500];
char outputFile[500];
for(;;){
cin >> choice;
if (choice != 'e' && choice != 'd')
cout << "Command not allowed. Try again." << endl;
cin >> key;
for (int i = 0; i < key.length(); i++){
if(!isalpha(key[i]))
cout << "Key invalid. Try again." << endl;
}
cin >> inputFile;
inFile.open(inputFile);
if (!inFile)
cout << "Can't open file " << inputFile << ". Try again." << endl;
cin >> outputFile;
outFile.open(outputFile);
if (!outFile)
cout << "Can't open file " << outputFile << ". Try again." << endl;
}
}