I'm attempting to use a while(1)
loop in the getCommand
function but it runs infinitely and doesn't break. I've included the HELP
function because it is called in the getCommand
function. Here is the code in question:
void HELP(string inCommand) {
if (inCommand == "invLoad?")
cout << "This command allows the user to load in new inventory information into the report." << endl;
else if (inCommand == "invReport?")
cout << "This command allows the user to access an inventory report of a requested item." << endl;
else if (inCommand == "invPriceUpdate?")
cout << "This command allows the user to update the prices of a requested item." << endl;
}
//This is the function that acquires the SIMS command from the user
string getCommand()
{
string commandInput = "";
char quit = '.';
cout << "Please enter the command for the Simple Inventory Management System:" << endl <<
"invLoad, invReport, invPriceUpdate." << endl << endl;
cout << "To learn what each command does add a '?' at the end of the command input" << endl;
cin >> commandInput;
while (1) {
if (commandInput == "invLoad") {
return "invLoad";
}
else if (commandInput == "invReport") {
return "invReport";
}
else if (commandInput == "invPriceUpdate") {
return "invPriceUPdate";
}
else if (commandInput == "invLoad?")
HELP(commandInput);
else if (commandInput == "invPriceUpdate?")
HELP(commandInput);
else if (commandInput == "invReport?")
HELP(commandInput);
else
cout << "Please enter an appropriate command!" << endl;
switch (quit)
{
case 'y':
return 0;
break;
case 'n':
cout << "Enter another command" << endl;
}
}
}
Unfortunately the while loop runs infinitely and I can't figure out how to break it.