Ok, so I'm trying to write a main where it will ask the user to enter a number 1 through 6 and if the number is 6 it will end the program. if it is higher than 6, it will ask to re-enter the number. The thing is, when I run it, it doesn't check the "if" statements and automatically goes to this line "please enter another option"
any thoughts why my program would do something like this?
UPDATE: I'm saying that it automatically skips all of the if
statements and asks the last question in the while
loop.
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.
}
}