string arr_function(string arr[], int max) {
for (int i = 0; i < max; i++) {
cout << "\n\t"
<< "[ " << arr[i] << " ]";
}
return 0;
}
int main() {
string arr[4] = {"Baseball", "Basketball", "Football", "Soccer"};
int one, two;
srand(time(NULL));
one = rand() % 4 + 1;
two = rand() % 4 + 1;
cout << arr_function(arr, one) << " " << arr_function(arr, two);
cout << endl;
return 0;
}
I have this function that prints an array. The program takes a random index from the array and prints it. I have several problems with it. It prints more than "1" and I only want "1" random sport.
The two calls to the function are because I want to randomize two different indexes and print possibly two random names (they could be the same though).
My other problem is that both function prints the name in a vertical line. I want to be able to print the two function in a horizontal line. I tried doing the following:
Change the void to string. I tried return arr[i], arr[max]
, etc. but that's wrong. I don't know how to return this type of function.
What I want to do with the output is
cout << arr_function(arr, one) << " " << arr_function(arr, two) << endl;
The final output I'm trying to get should look like,
[Baseball] [Basketball]