#include #include using namespace std; const int size = 30; char filename[size]; //char menu; bool isNotvalidate(int); void choose(int); char ext[4]; char newname[size+5]; void extension(int, char ext[]); void append(char filename[], char ext[], char newname[]); int main() { int choice; ifstream inputfile; do { cout << "What file contains your data? "; cin >> filename; cout << "1] .txt " << endl; cout << "2] .dat " << endl; cout << "3] .in " << endl; cout << "4] .ttd " << endl; cout << "What is the file extension?" << endl ; cin >> choice; }while(isNotvalidate(choice)); choose(choice);//SHows you the file extension you chose extension(choice, ext); append(filename, ext, newname); inputfile.open(newname);// open the file given cin.ignore(); cin.ignore(); return 0; } bool isNotvalidate(int choice) { if(choice < 1 || choice > 4) return true; else return false; } //char menu() //{ //} void choose(int choice) { switch(choice) { case 1: cout << "Opening file " << filename << ".txt" << endl; break; case 2: cout << "Opening file " << filename << ".dat" << endl; break; case 3: cout << "Opening file " << filename << ".in" << endl; break; default: cout << "Opening file " << filename << ".ttd" << endl; break; } } void append(char filename[], char ext[], char newname[]) { for(int count=0; char filename[count] != '\0'; count++) newname[count] = filename[count]; for(int j=0; char ext[j] != '\0'; j++) newname[count] = ext[j]; newname[count] = '\0'; } void extension(int choice, char ext[]) { if(choice == 1) char ext[] = '.txt'; else if(choice == 2) ext = '.dat'; else if(choice == 3) ext = '.in'; else if(choice == 4) ext = '.ttd'; }