I have two arrays in C ++ , one with the names of people and another with the ages.
How could I find the person younger and show it on the screen?
Example:
Alejandro 37
Tatiana 28
Maria 52
... and show on the screen, The youngest person is Tatiana.
I have this code:
int n;
char nombre[8][20];
int edad[8];
int numero[100];
int menor=100;
cout<<"Digite la cantidad de jugadores: ";
cin>>n;
for(int i=0;i<n;i++){
cout<<"\nDigite el nombre del jugador "<<i+1<<" : ";
cin>>nombre[i];
cout<<"Digite la edad del jugador "<<i+1<<" : ";
cin>>edad[i];
}
cout<<"\n";
for(int i=0; i<n; i++){
cout<<"Jugador "<<i+1<<" -> "<<nombre[i]<<endl;
}
for(int i=0; i<n; i++){
if(edad[i] < menor){
menor = edad[i];
cout<<"\nEl menor elemento del vector es: "<<nombre[i]<<" "<<menor<<endl;
}
}
... and print this screen:
Type the number of players: 4
Type the name of player 1: Maria
Enter the age of the player 1: 52Type the name of player 2: Juan
Enter the age of the player 2: 20Type the name of player 3: Pablo
Enter player's age 3: 14Type the name of player 4: Carmen
Enter player's age 4: 32Player 1 - > Maria
Player 2 - > Juan
Player 3 - > Pablo
Player 4 - > CarmenThe smallest element of the vector is: María 52
The smallest element of the vector is: Juan 20
The smallest element of the vector is: Pablo 14
I need you to print me in this case: The smallest element of the vector is: Pablo 14
This is because Pablo is the youngest.