Uninitialized Local Variable within Case block.
May 21, 2013 at 9:56am UTC
Hi again, I am having problems with my case block. Within it is a variable called userChoice. This variable stores the user's input. I don't know why I am getting this warning, any ideas? Any help again, would be greatly appreciated!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
int main(){
int numInsert;
LinkedList list;
int userChoice;
displayMenu();
do {switch ( userChoice )
{
cin >> userChoice;
case 1:
cout << "Enter number to be inserted: " << endl;
cin >> numInsert;
list.insertAtFront(numInsert);
break ;
case 2:
cout << "Enter a number to be inserted: " << endl;
cin >> numInsert;
list.insertAtBack(numInsert);
break ;
case 3:
cout << "Enter number to be deleted: " << endl;
cin >> numInsert;
list.removeFromFront(numInsert);
break ;
case 4:
cout << "Enter number to be deleted: " << endl;
cin >> numInsert;
list.removeFromBack(numInsert);
break ;
case 5:
cout << "List = " << endl;
list.print();
break ;
case 6:
cout << "Exiting Program!" << endl;
break ;
default :
cout << "Error, bad input!" << endl;
break ;
} }while (userChoice != 6);
system("pause" );
}
Last edited on May 21, 2013 at 9:56am UTC
May 21, 2013 at 9:59am UTC
line 11 is supposed to be before switch
Topic archived. No new replies allowed.