I recoded my function, but it is still stopping my program after the user enters the input. The function should return the char value if the user enters a valid letter (A through I or X). But, it just stops after the input is entered.
Code:
char accept_item_code ()
{
char c;
bool valid = false;
cout << endl << "--------------------" << endl;
cout << "Enter product code: ";
cin >> c;
c = toupper(c);
cout << c;
cout << endl;
while (!valid)
{
if (c == 'A' || c == 'B' || c == 'C' || c == 'D' || c == 'E')
{
valid = true;
}
else if (c == 'F' c == 'G' || c == 'H' || c == 'I' || c == 'X')
{
valid = true;
}
else
{
cout << "!!! Invalid product code" << endl << endl
<< "Enter product code: ";
cin >> c;
c = toupper(c);
cout << endl;
}
}
return c;
}
Josh Stevanus
[email protected]