わかりましたので、ユーザーに 1 から 6 までの数字を入力するように要求し、数字が 6 の場合はプログラムを終了するメインを作成しようとしています。6 より大きい場合は、番号の再入力を求められます。問題は、実行すると「if」ステートメントがチェックされず、「別のオプションを入力してください」という行に自動的に移動することです。
私のプログラムがこのようなことをする理由は何ですか?
更新: すべてのステートメントを自動的にスキップし、ループif
内の最後の質問を行うと言っています。while
int main()
{
int userChoice = 0;
print(); //printing all of the options.
cout << "Please enter one of the options listed below" <<endl;
cin >> userChoice;
while(userChoice != 6)// 6 = the user wishing the end the program when they press 6.
{
if(userChoice == 1) //adding integer to the front of the list
{
addValueFront();
}
else if(userChoice == 2)//adding integer to the back of the list
{
addValueBack();
}
else if(userChoice == 3)//removing from the list
{
int n = 0;
cout << "Please enter the integer you wish to remove" << endl;
cin >> n;
removeValue(n);
}
else if(userChoice == 4)//printing the list
{
printList();
}
else if(userChoice == 5)//printing the number of items from the list
{
printItem();
}
else
{
cout << "The number you have entered is too high. Please try again" << endl;
cin >> userChoice;
}
cout << "please enter another option" <<endl;
cin >> userChoice; //sets up which option the user can choose from.
}
}