好的,所以我正在尝试编写一个主程序,它将要求用户输入数字 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.
}
}