char choice;
cout << "Enter A to add an item, D to delete an item, S to search for an item, L for the length of the list, P to print list, or E to exit:"<< endl;
cin >> choice;
while ((choice=!'E')||(choice!='e'))
{
{
if ((choice=='A')||(choice=='a'))
{
cout << "Enter the integer you want to add:" << endl;
cin >> userEnteredInt;
addItem(userEnteredInt, intList);
}
elseif ((choice=='D')||(choice=='d'))
{
cout << "Enter the integer you wish to delete:" << endl;
cin >> userEnteredInt;
deleteItem(userEnteredInt, intList);
}
elseif((choice=='S')||(choice=='s'))
{
cout << "Enter the integer you wish to search for:" << endl;
cin >> userEnteredInt;
searchItem(userEnteredInt, intList);
}
elseif((choice=='L')||(choice=='l'))
{
lengthList(intList);
}
elseif((choice=='P')||(choice=='p'))
{
printList(intList);
}
else
cout <<"Invalid Entry" <<endl;
}
cout << "Enter A to add an item, D to delete an item, S to search for an item, L for the length of the list, P to print list, or E to exit:"<< endl;
cin >> choice;
}
For every letter I enter, it return "invalid entry". Am I doing something wrong, or is my compiler out of control? I have included string and iostream.
If the amount of code in a case clause is getting too much then call a function from the case.
HTH
BTW You can build up cout statements in parts - there is no need to have all the code in 1 line, this is equivalent:
1 2 3
cout << "Enter A to add an item, D to delete an item,";
cout << " S to search for an item, L for the length of the list,";
cout << " P to print list, or E to exit:"<< endl;
The condition of the while loop is, from what I believe, erroneous. The not operator is performing an operation on the given character literal and then assigning that value to choice. Your program would function as expected if you were to switch the two operators (=, !).