According to what I put, if the name is = END the loop ends, but instead of doing that, just when I put the first name (whatever it is) the program begins to enter an infinite loop:
int main()
{
int edad, edadmayor, edadmenor, i;
char nombre, nombremayor, nombremenor;
edadmayor=0;
edadmenor=0;
nombre=' ';
do
{
cout << "Ingrese el nombre de la persona y la fecha de nacimiento en formato AAAAMMDD" << endl;
cin >> nombre;
cin >> edad;
if (edadmayor<edad)
{
edadmayor=edad;
nombremayor=nombre;
}
else if (edadmenor>edad)
{
edadmenor=edad;
nombremenor=nombre;
}
cout << "Si no quiere ingresar otro nombre, coloque 'FIN', si quiere seguir ingresando, toque cualquier tecla" << endl;
cin >> nombre;
} while (nombre!='FIN');
cout << "La persona mas grande se llama " << nombremenor << " y nacio el " << edadmenor << endl;
cout << "La persona mas joven se llama " << nombremayor << " y nacio el " << edadmayor << endl;
return 0;
}
A character ( ) is not the same as a character
char
string. A character can contain only one letter; so it can never contain the three letters that make up the stringFIN
.On the other hand, in c++ character strings are delimited with double quotes (
"
) if you delimit a word of four or fewer letters with single quotes ('
) what you get is an integer literal, in your case4606286
that in hexadecimal is0x46494E
that it is corresponds to the hexadecimal values of the lettersF
,I
andN
(0x46
is F ,0x49
is I and0x4E
is N ).So you've done it all wrong: