My code has two structs, Players[200 MAX] and Characters[30 MAX]. To register a player I have to check if there is space in the array and if the user name is > than 5 characters. After that I can ask for the other data. All has to be with functions, so I'm trying to do a function for the space in the array check and another for the verification of the size.
To be honest I don't know how to handle this, I lost some classes about functions with structs and lost all my mind, was looking on the Internet but there's not a lot of information about this.
#include <iostream>
#include <string>
using namespace std;
const int MAX_P = 200;
const int MAX_J = 30;
struct Personatge
{
int Numero;
string Nom;
char Tier;
float Pes;
};
struct Jugadors
{
string Username;
string Nom;
bool Amateur;
int PJfav;
};
int menu();
void altaJugador(Jugadors* jugs);
void main() {
Personatge vectorPersonajes[MAX_P];
Jugadors vectorJugadores[MAX_J];
int opcion = menu();
switch (opcion)
{
case 1:
altaJugador(vectorJugadores);
break;
case 2:
break;
case 3:
break;
case 4:
break;
default:
break;
}
system("pause");
}
int menu() {
int eleccion;
cout << "SSBU CEP Tournament \n";
cout <<
"1. Alta jugador \n" <<
"2. Establir personatge favorit \n" <<
"3. Mostrar jugadors \n" <<
"4. Baixa jugador \n" <<
"5. Alta personatge (manual) \n" <<
"6. Llistat de personatges d'un tier \n" <<
"0. Sortir \n";
cout << "Opcio: \n";
do
{
cin >> eleccion;
if (eleccion < 0 || eleccion > 6)
{
cout << "Error, tria un numero del 0 al 6 \n";
}
} while (eleccion < 0 || eleccion > 6);
return eleccion;
}
void altaJugador(Jugadors *jugs) {
cout << "Introduce el username del jugador: \n";
getline(cin, (jugs->Username));
cout << "Introduce el nombre y el apellido: \n";
getline(cin, (jugs->Nom));
cout << "Eres amateur? S/N: \n";
cin >> jugs->Amateur;
cout << "Introduce el numero de tu personaje favorito: \n";
cin >> jugs->PJfav;
}
MAX_PandMAX_J.std::vectorinstead of arrays.