Hello everyone,
I need to write code such that:
.you can select number of players(2,3or4) and put that number in array..
.display message if correct number not entered.
.then each player must be able to choose their color(red, blue, yellow,green)
.two players cannot be assigned the same colour
This is what i have done.. Can someone tell me if it is the right way to do this? its a bit length...
int num_players,p1color,p2color,p3color,p4color;
char player_color;
int players[1];
bool selectred,selectblue,selectyellow,selectgreen;
cout<<"Select number of players: ";
cin>>num_players;
players[0]=num_players;
if((num_players>=2) && (num_players<=4))
{ switch(num_players)
{ case 2:
cout<<"Player 1, Choose your house(R for Red,B for Blue,Y for Yellow,";
cout<<"G for Green" <<endl;
cin>>p1color;
if(p1color=='R' || 'r')
{ cout<<"Player 1 is initialised Red";
selectred=true;
selectblue=false;
selectyellow=false;
selectgreen=false;
}
else if(p1color=='B' || 'b')
{ cout<<"Player 1 initialises Blue" ;
selectred=false;
selectblue=true;
selectyellow=false;
selectgreen=false;
}
else if(p1color=='Y' || 'y')
{ cout<<"Player 1 initialises Yellow" ;
selectred=false;
selectblue=false;
selectyellow=true;
selectgreen=false;
}
else if(p1color=='B' || 'b')
{ cout<<"Player 1 initialises Green" ;
selectred=false;
selectblue=false;
selectyellow=false;
selectgreen=true;
}
}
}
//case 2..
cout<<"Error!Please enter a valid number of players(2,3 or 4)" <<endl;
cout<<"Select number of players: ";
cin>>num_players;
players[0]=num_players;