Hi all
I've only just started using the C++ language recently and I'm stuck on something which should be pretty easy but I can't solve.
option is defined as char option[80]. My main problem is that if I enter an option of 9, "PLEASE TRY AGAIN" comes up. I want this to happen if say 22 is entered as well but currently Case 2 is selected, not the default. Why is it doing this and how would I sort it?
Code:
do {
cout << "\n Products\n";
cout << " 1. New\n";
cout << " 2. Old\n";
cout << " 3. Discontinued\n";
cout << " q. End menu\n";
cout << "\n\n";
cout << "\n Press appropriate key to select > ";
gets(option);
switch (option[0]) {
case '1':
new(items);
key();
break;
case '2':
old(items);
key();
break;
case '3':
discontinued(items);
key();
break;
case 'q':
cout <<("\n\t\t Returning to main.\n");
key();
break;
default:
cout <<("\t\t PLEASE TRY AGAIN\n");
key();
break;
} //end switch
}//end do
while (option[0] != 'q' );
break;