私はプロジェクトの第2フェーズにあり、プログラムをメニュー方式のアプリケーションに拡張して、.txtファイルにあるデータベースをクエリする必要があります。ですから、私の問題は、ループを永続的にすることができないということです。あるオプションから次のオプションに初期化すると、常に終了します。これが私のintメインである私のコードのスニペットです:
int main ()
{
char Q,q;
char S,s;
char task;
string pathname;
string z;
int count=0;
cout << "Welcome to Jason Rodriguez's Library Database." << endl;
cout << "Please enter the name of the backup file: ";
cin >> pathname;
ifstream inFile(pathname.c_str());
while(!inFile.eof())
{
getline(inFile,z);
count++;
}
while (task != 'Q' || task != 'q') {
cout << count << " records loaded successfully." << endl;
cout << "Enter Q to (Q)uit, Search (A)uthor, Search (T)itle, (S)how All: ";
cin >> task;
if ((task == 'Q')||(task =='q'))
{
cout << "Program will now terminate";
break;
}
else if ((task == 'S')||(task =='s'))
{
showAll (loadData (pathname));
cout << endl;
cout << "Enter Q to (Q)uit, Search (A)uthor, Search (T)itle, (S)how All: ";
cin >> task;
}
}
}
これら2つに加えて、ループにさらに2つのオプションを追加する必要がありますが、最初に最初の2つを正しく機能させる必要があると考えました。その後、他の2つはプラグアンドチャグする必要があります。基本的に私がやろうとしていたのは、ユーザーがQまたはqを入力したら、プログラムを終了するということです。それ以外の場合、ユーザーがSまたはsを押した場合は、showall機能をアクティブにして、ワードの後で元のクエリに戻ります。しかし、それは機能していません。支援は大歓迎です。