好吧,所以我想写一个主要的地方,它会要求用户输入一个数字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.
}
}
标题不太具描述性。 – chris 2013-03-02 04:31:07
定义“不工作”。我敢打赌,它正在发挥作用,并且确实遵循了那里的代码告诉它要做的事情。 – 2013-03-02 04:31:51
你是不是指'while(userChoice!= 6)'? – 2013-03-02 04:32:28