cout string
Publicado por Juan (3 intervenciones) el 19/08/2017 15:20:35
Tengo un problema con este código que es muy simple. No logro que imprima la cadena maximoNombre, cualquier ayuda se agradece.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <stdio.h>
#include <string.h>
//using namespace std;
const int tamanio=3;
struct REG{
std::string nombre;
int fecha;
};
int main (){
REG arr[tamanio];
std::string nom;
int data;
int j=0;
std::cout << "Ingrese nombre, FIN para terminar: ";
std::cin >> nom;
while (nom != "FIN" && j < tamanio){
arr[j].nombre=nom;
std::cout << "Ingrese fecha de nacimiento (AAAAMMDD): ";
std::cin >> data;
arr[j].fecha = data;
j++;
std::cout << "Ingrese nombre, FIN para terminar: ";
std::cin >> nom;
}
int maximoEdad = arr[0].fecha;
std::string maximoNombre=arr[0].nombre;
for (int i = 1; i < tamanio; i++){
if (arr[i].fecha < maximoEdad){
maximoEdad = arr[i].fecha;
maximoNombre = arr[i].nombre;
}
}
std::cout<<"El nombre de la persona de mayor edad es "<<maximoNombre;
}
Valora esta pregunta
0