mardi 29 octobre 2019

Infinite do-while loop in c++

This function displayMenu() is being called in Main under the condition while(menuChoice != Q), but the function itself has an internal infinite loop. Any help on why the loop in the display menu function is infinite would be great... I think it may be something to do with the do-while structure or the relational operator != working improperly.

FUNCTION DISPLAYMENU:
char displayMenu()
{
// can be useful info during development
cout << "Entered function displayMenu..." << endl;

char whatToDo = '?';


do {
    //Display Menu Options
    cout <<"Upload a regional sales data file \tU" <<endl;
    cout <<"display details (All loaded data) \tA" <<endl;
    cout <<"list details for specific Order number \tO" <<endl;
    cout <<"display summary by Region \tR" <<endl;
    cout <<"display summary by print method \tM" <<endl;
    cout <<"Clear all data \tC" <<endl;
    cout <<"Quit \tQ" <<endl;
    cout <<"\nPlease Enter Your Menu Choice: " <<endl;
    cin >> whatToDo;
} while (whatToDo != 'U' ||
         whatToDo != 'A' ||
         whatToDo != 'O' ||
         whatToDo != 'R' ||
         whatToDo != 'M' ||
         whatToDo != 'C' ||
         whatToDo != 'Q');

// can be useful info during development
cout << "Returning " << whatToDo << " from displayMenu..." << endl;

return whatToDo;

} // END function displayMenu()


FUNCTION MAIN 
while (menuChoice != 'Q'){
    menuChoice = displayMenu();
}

Aucun commentaire:

Enregistrer un commentaire