I am trying to make a simple game with multiple players, but the number of players is determined by the user. The number is passed into an array where the names of the players are stored, however my program crashes after i finish entering the player's names. Can anyone help me figure what I am doing wrong?
#include<iostream>
#include<string>
usingnamespace std;
int main()
{
int numPlayers;
cout << "How many players are there? >> ";
cin >> numPlayers;
string *name = new string[numPlayers]; //Create array with length of numPlayers
for (int x = 1; x <= numPlayers; ++x) //Populate the array
{
cout << "Enter player " << x << "'s name >> ";
cin >> name[x];
}
cout << endl;
return 0;
}