Help me fix my code!!

You should prompt the user to input either 1 or 2, signifying they prefer either the first or second restaurant, respectively
If the user provides a response that is neither of the restaurants in the current match, reprompt the user until valid information is entered

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
  string tournament(vector<string>&restaurants)
{
	const int POWER_BASE = 2;
	int integerExponent = log(restaurants.size()) / log(POWER_BASE);
	double doubleExponent = log(restaurants.size()) / log(POWER_BASE);
	int i = 0;
	vector<string> losers;
	string restaurantName = "";

	if (doubleExponent == integerExponent)
	{
		do
		{
			for (int i = 0; i < restaurants.size() - 1; i += 2)
			{
				string opponent1 = restaurants[i];
				string opponent2 = restaurants[i + 1];
				cout << endl << "1. " << opponent1 << " or " << "2. "<< opponent2 << endl;
				string winner;
				getline(cin, winner);

				while (winner != restaurants[i] && winner != restaurants[i + 1])
				{
					cout << "Invalid, please re-enter" << endl;
					getline(cin, winner);

				}
				if (winner == opponent1)
				{
					restaurantName = opponent2;
					losers.push_back(restaurantName);
				}
				else if (winner == opponent2)
				{
					restaurantName = opponent1;
					losers.push_back(restaurantName);
				}
			}
			for (int i = 0; i < losers.size(); i++)
			{
				restaurantName = losers[i];
				removeLoserRestaurant(restaurantName, restaurants);
			}
			losers.clear();
			printRestaurants(restaurants);
		} while (restaurants.size() > 1);
		cout << "The winner is " << restaurants[0] << endl;
	}
	else
	{
		cout << "Could not begin tournament. There is not enough restaurants in the tournament. Please add or remove a restaurant." << endl;
	}
	return restaurantName;
}
Topic archived. No new replies allowed.