I'm a beginner in C ++ (even because the code is basic) and I'm having a problem with an exercise that needs to save the data of 10 people (name, date of birth and height) using structs.
The structs are:
typedef struct
{
char nome[50];
float altura;
} pserhumano;
typedef struct
{
float dia;
float mes;
float ano;
} dnasc;
And the two functions are:
void CriaData(dnasc *D[], int i)
{
D[i]->mes = 1 + (rand() % 12);
D[i]->ano = 1950 + (rand() % 49);
D[i]->dia = 1 + (rand() % 30);
}
void InserirNome(pserhumano *Z[])
{
dnasc a[10];
for (int contador = 0; contador < 10; contador++) {
cout << "Insira o seu nome." << endl;
gets (Z[contador]->nome);
cout << "Insira a sua idade." << endl;
cin >> Z[contador]->altura;
CriaData(&a, contador);
}
}
When compiling, the output is this:
athos@ubuntu:~$ g++ exercicio1.cpp -w -o a
exercicio1.cpp: In function ‘void InserirNome(pserhumano**)’:
exercicio1.cpp:35:33: error: cannot convert ‘dnasc (*)[10]’ to ‘dnasc**’ for argument ‘1’ to ‘void CriaData(dnasc**, int)’
CriaData(&a, contador);
^
exercicio1.cpp: In function ‘int main()’:
exercicio1.cpp:43:19: error: cannot convert ‘pserhumano (*)[10]’ to ‘pserhumano**’ for argument ‘1’ to ‘void InserirNome(pserhumano**)’
InserirNome(&b);
^
Basically, I'm having trouble dealing with a struct vector and it's time to move it to function. What could be done?