OK trying something to help out a local team....
total players = 2 - 30
each team (at first is equal players, unless there is an odd man, then they are in team two)
game is played....
at the end, losing team loses a player
game played again
losing team loses player, system repeats
when the admin decides, all the players are re suffled to two even teams, then cycle repeats...
using a 1d array, i can start the players, add a player, manually delete a player BUT onec a team loses too many, then probs start and players "dissapper" one teams...
is a 1d array the right way to go?
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <time.h>
#include <string.h>
int main(void)
{
char array[30][255];
int totalplayers;
int choice;
//GET TOTAL NUMBER OF PLAYERS//
printf("Total Number of Players (1-30): ");
scanf("%i",&totalplayers);
//ENTER PLAYERS NAMES//
for(int n=0;n<totalplayers;n++)
{
printf("Enter Player # %i`s Name: ",n+1);
scanf("%s", &*array[n]);
}
//PRINT NAMES ENTERED//
system("cls");
printf("Current List of players\n");
for(int n=0;n<totalplayers;n++)
{
printf("%s\n",array[n]);
}
system("pause");
//PRINT MENU FOR CHOICES//
do
{
system("cls");
do
{
printf("Menu\n");
printf("1.Randomize Teams\n");
printf("2.Add Player to list\n");
printf("3.View Teams\n");
printf("4.Manually remove player\n");
printf("5.Randomly Remove player from Team\n");
printf("6.Exit\n");
printf("Choice: ");
scanf("%i",&choice);
}while(choice>6||choice<1);
switch(choice)
{
case 1://randomize teams
srand ( time(NULL) );
for (int i = totalplayers-1; i > 0; i--)
{
int j = rand() % (i+1);
if ((strcmp(array[j]," ")!=0)&&(strcmp(array[i]," ")!=0))
{
char temp[255];
temp[0] = *array[i];
*array[i] = *array[j] ;
*array[j] = temp[0];
}
else
{
i=i-1;
}
}
system("cls");
printf("Team 1\t\t\tTeam2\n");
for(int n=0;n<totalplayers;n++)
{
printf("%s\t\t\t",array[n]);
n++;
printf("%s\n",array[n]);
}
system("pause");
break;
case 2:
if(totalplayers<30)
{
system("cls");
totalplayers++;
printf("Enter Player # %i`s Name: ",totalplayers);
scanf("%s", &*array[totalplayers-1]);
//PRINT NAMES ENTERED//
system("cls");
printf("Current List of players\n");
for(int n=0;n<totalplayers;n++)
{
printf("%s\n",array[n]);
}
system("pause");
}
else
{
system("cls");
printf("Already at max players!!!\n");
system("pause");
}
break;
case 3:
system("cls");
printf("Team 1\t\t\tTeam2\n");
for(int n=0;n<totalplayers;n++)
{
printf("%s\t\t\t",array[n]);
n++;
printf("%s\n",array[n]);
}
system("pause");
break;
case 4://manually remove player from team
system("cls");
printf("Team 1\t\t\tTeam2\n");
for(int n=0;n<totalplayers;n++)
{
printf("%i.%s\t\t\t",n+1,array[n]);
n++;
printf("%i.%s\n",n+1,array[n]);
}
do
{
printf("Which player to delete (1-%i) ",totalplayers);
scanf("%i",&choice);
}while(choice<1||choice>totalplayers);
*array[choice-1]=' ';
for(int m=choice-1;m<totalplayers;m=m+2)
*array[m]=*array[m+2];
system("cls");
printf("Team 1\t\t\tTeam2\n");
for(int n=0;n<totalplayers;n++)
{
printf("%i.%s\t\t\t",n+1,array[n]);
n++;
printf("%i.%s\n",n+1,array[n]);
}
break;
case 5:
printf("5");
break;
case 6:
printf("6");
break;
}
}while(choice!=6);
return 0;
}