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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;
// prints a list of restaurants separated by commas, without a trailing comma.
void print_restaurants(vector <string> restaurant) {...}
// Checks to see if the restaurant is already on the list or not.
bool find_restaurant(string selected_restaurant, vector <string> restaurant, int f) {
if (restaurant[f] == selected_restaurant) {
return true;
}
else {
return false;
}
}
// Adds a restaurant to the list if it is not already on the list.
bool add_unique(string name, vector <string> &restaurant) {...}
// Removes a restaurant from the list, if it is already on the list.
bool remove_match(string removal, vector <string> &restaurants) {
for (int i = 0; i < restaurants.size(); i++) {
do {
if (find_restaurant(removal, restaurants, i)) {
restaurants.erase(restaurants.begin() + i);
return true;
}
} while (find_restaurant(removal, restaurants, i));
}
return false;
}
//Randomly rearranges the order of the restaurants in the list.
void randomized(vector <string> &restaurants) {...}
//Determines if the tournament has the correct number of participants.
bool power_of_two(vector <string> restaurants) {
int x = restaurants.size();
while (((x % 2) == 0) && x > 1) {
x /= 2;
if (x == 1) {
return true;
}
}
return false;
}
int main() {
vector <string> restaurants;
restaurants.push_back("Blue Lemon");
restaurants.push_back("Habit Burger");
restaurants.push_back("Pizza Studio");
restaurants.push_back("Bombay House");
restaurants.push_back("Mountain West Burrito");
restaurants.push_back("Apple Smoke");
restaurants.push_back("Potbelly's");
restaurants.push_back("Cafe Rio");
string option;
do {
cout << "Lets figure out where to eat\n"
"\t1 - Display all restaurants\n"
"\t2 - Add a restaurant\n"
"\t3 - Remove a restaurant\n"
"\t4 - Shuffle the array\n"
"\t5 - Begin the tournament\n"
"\t6 - Quit the program\n"
"Enter one of the listed options: ";
cin >> option;
if (option < "1" || option > "6") {
cout << endl << "That is an invalid selection. Please chose one of the options"
<< "between 1 and 6." << endl << endl;
}
// Display all restaurants
if (option == "1") {...}
// Add a restaurant
else if (option == "2") {...}
// Remove a restaurant
else if (option == "3") {...}
// Shuffle the array
else if (option == "4") {...}
***Here is the part I need help with***
// Begin the tournament
else if (option == "5") {
if (power_of_two(restaurants)) {
cout << "Beginning the Tournament.\n";
int num = restaurants.size();
double rounds = log(num) / log(2);
cout << "There will be " << rounds << " round(s)" << endl;
for (int r = 1; r <= rounds; r++) {
num /= 2;
cout << "Round " << r << " will have " << num << " match(es)" << endl;
}
do {
for (int r = 0; r <= rounds; r++) {
for (int m = 0; m < num; m++) {
cout << "Match " << m + 1 << "/" << num << ", Round " << r + 1 << "/" << rounds << endl;
cout << restaurants[m] << "' or '" << restaurants[m + 1] << "'";
string winner;
cin.sync();
cin.ignore();
getline(cin, winner);
cout << winner << endl;
if (winner == restaurants[m]) {
remove_match(restaurants[m + 1], restaurants);
}
else if (winner == restaurants[m + 1]) {
remove_match(restaurants[m], restaurants);
}
else {
cout << "That was not a choice." << endl;
}
}
}
} while (restaurants.size() > 0);
}
else {
cout << "You have not entered enough restaurants to complete the bracket, add more.";
}
}
cout << restaurants.size() << endl;
cout << restaurants[0] << endl;
cout << "Now select \"6 - Quit the program.\" and go to dinner!\n\n";
} while (option != "6");
system("pause>null");
return 0;
}
|