Hello. I am having trouble with the functions in my program, particularly the getChoice function and how to flesh that out to properly follow the guidelines of my Professor. Here is the assignment:
char getChoice()
{
char choice;
cout << "Enter your choice: ";
cin >> choice;
return choice;
}
int main()
{
UnsortedList list;
showMenu();
char choice = getChoice();
if (choice == 'a') {
int num;
cout << "Enter a number: ";
cin >> num;
list.insertItem(num); // TO DO: check for full list
} elseif (choice == 'b') {
int num;
cout << "Enter a number to be deleted: ";
cin >> num;
list.deleteItem(num); // TO DO: Check for empty list
}
}
I'm getting an error under "showMenu();" it says that it's "identifier is undefined"...there are no other redlines. Would you happen to know why this is happening? Thanks.
int main()
{
UnsortedList list;
list.showMenu();
char choice = getChoice();
if (choice == 'a') {
while (!list.isFull()) {
int num;
cout << "Enter a number: ";
cin >> num;
list.insertItem(num); // TO DO: check for full list
if (list.isFull())
cout << "List is full." << endl;
}
}
elseif (choice == 'b') {
int num;
cout << "Enter a number to be deleted: ";
cin >> num;
list.deleteItem(num); // TO DO: Check for empty list
if (list.isEmpty())
cout << "The list is empty." << endl;
}
list.displayList();
}
int main()
{
UnsortedList list;
list.showMenu();
while (!list.isFull() || list.isEmpty()) {
char choice = getChoice();
if (choice == 'a') {
int num;
cout << "Enter a number: ";
cin >> num;
list.insertItem(num);
if (list.isFull())
cout << "List is full." << endl;
}
elseif (choice == 'b') {
int num;
cout << "Enter a number to be deleted: ";
cin >> num;
list.deleteItem(num);
if (list.isEmpty())
cout << "The list is empty." << endl;
}
}
list.displayList();
}