I always seem to have this problem when I want to display two variables of an array in one iteration of a loop, I'm wondering if there is a nicer way of displaying the array.
The code works if I change ++i to i+1 but I'm wondering why that happens, and I'm wondering if there's a smarter way to do what I want. The error says unsequenced modification and access to 'i' [-Wunsequenced]
#include <iostream>
#include <memory>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int players = 0,rounds=0;
bool winnerFound=false;
cout << "Welcome to my tournament match maker\n";
cout << "Enter the number of participants in the tournament: ";
cin >> players;
rounds=players/2;
string *pNames = new string[players]; //dynamically allocate
for (int i = 0;i < players;i++)
{
cout << "Enter the name of player " << i + 1<<":";
cin >> pNames[i];
}
random_shuffle(&pNames[0],&pNames[players]);
for(int i=0;i<rounds;i++)
{
cout<<pNames[i]<<" vs "<<pNames[++i]; //
}
return 0;
}
I'm not sure if that's the best way to do it, any tips would be appreciated.