do/while Loop not working
Jun 1, 2016 at 3:38am UTC
I cannot for the life of me figure out why this loop is not working. It should restart the program when a user selects one of the valid inputs, but instead the program exits and ignores the do/while loop and the system("pause") at the end.
For simplicity's sake, I'm just including my main() section and not the functions that accompany it because I don't think they're relevant to this problem. If anybody would like me to include them, I would be happy to oblige.
Any suggestions on what I'm doing wrong here?
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include <iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
vector <string> restaurants;
restaurants.push_back("J&C House" );
restaurants.push_back("Sushi Burrito" );
restaurants.push_back("Cubby's" );
restaurants.push_back("Red Robin" );
restaurants.push_back("Boudreaux's" );
restaurants.push_back("Domino's" );
restaurants.push_back("Jimmy John's" );
restaurants.push_back("Tucanos" );
string option;
do
{
cout << "Please choose an option:" << endl;
cout << "A: Display all restaurants" << endl;
cout << "B: Add a restaurant" << endl;
cout << "C: Remove a restaurant" << endl;
cout << "D: Shuffle the vector" << endl;
cout << "E: Begin the tournement" << endl;
cout << "F: Quit program" << endl;
cin >> option;
string userRestaurant;
if (option == "A" || option == "a" )
{
optionA(restaurants);
}
if (option == "B" || option == "b" )
{
cout << "Please type the name of the restaurant you would like to add:" ;
cin.ignore();
getline(cin, userRestaurant);
if (find(restaurants.begin(), restaurants.end(), userRestaurant) != restaurants.end())
{
cout << "We already have that restaurant." ;
}
else
{
cout << "Your restaurant has been added." << endl;
add(restaurants, userRestaurant);
optionA(restaurants);
}
}
if (option == "C" || option == "c" )
{
cout << "Which restaurant would you like to remove? " ;
cin.ignore();
getline(cin, userRestaurant);
if (find(restaurants.begin(), restaurants.end(), userRestaurant) != restaurants.end())
{
remove(restaurants, userRestaurant);
}
else
{
cout << userRestaurant << " is not on the list." << endl;
cout << endl;
}
optionA(restaurants);
}
if (option == "D" || "d" )
{
random_shuffle(restaurants.begin(), restaurants.end(), random);
}
if (option == "E" || "e" )
{
}
if (option == "F" || "f" )
{
exit(0);
}
} while (option == "A" || "a" || "B" || "b" || "C" || "c" || "D" || "d" || "E" || "e" );
system("pause" );
return 0;
}
Jun 1, 2016 at 4:07am UTC
} while (option == "A" || option == "a" || option == "B" || /*etc.*/ );
Your ifs on lines 75, 80, and 85 are incorrect for the same reason.
Jun 1, 2016 at 4:17am UTC
You, sir, are a saint and a scholar. Thank you so much!
Topic archived. No new replies allowed.