Players play in fixed order

Hi,
I wanna play a game in which each player can call a function etc.
My goal is now that i can select the 1st player in an array and this player can
call up some functions. After he did this, the next player is in order.
Hes doing the same as the player before him.
Thats how i set the number of Players:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
void rolldice();
bool prooftruth();


int numberofplayers;
cout << "Number of Players: ";
cin >> numberofplayers;

string *player = new player[numberofplayers];



for(int i = 0; i < numberofplayers;i++)
{
cout << "Tell me your name: ";
cin >> player[i];
}

Can someone give me some input?

Greetings
Last edited on
¿what's your question?
Use a vector instead of a variable length array. Also, create a Player class that stores the state of a player.
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
#include <vector>
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::vector;
using std::string;

void rolldice();
bool prooftruth();

class Player {
public:
    string name;
    // other stuff
};

int main()
{
    int numberofplayers;
    cout << "Number of Players: ";
    cin >> numberofplayers;

    vector<Player> players(numberofplayers);
    for (unsigned i=0; i<players.size(); ++i) { // consider range-based loop instead
	cout << "Tell me your name: ";
	cin >> players[i].name;
    }

    for (unsigned i=0; i<players.size(); ++i) { // consider range-based loop instead
	// Do Stuff with players[i]
    }
}

Topic archived. No new replies allowed.