Buenas, se supone que esta funcion tiene que mostrar los libros de una struct entre dos fechas introducidas por el usuario:
void MostrarLibrosFechas (Libros libros)
{
Fecha fm, fM;
Libro lib;
int i = 1;
cout << "Escribe la fecha menor: " << endl << endl;
fm = PedirFecha ();
cout << "Escribe la fecha mayor: " << endl << endl;
fM = PedirFecha ();
for (int j = 0; j <= libros.num; j++)
{
if (fm.anyo >= libros.vect[j].fecha.anyo && fM.anyo <= libros.vect[j].fecha.anyo)
{
cout << "Libro " << i << " : " << endl << endl;
lib = libros.vect[j];
MostrarLibro (lib);
i++;
}
else if (fm.anyo == libros.vect[j].fecha.anyo)
{
if (fm.mes >= libros.vect[j].fecha.mes)
{
cout << "Libro " << i << " : " << endl << endl;
lib = libros.vect[j];
MostrarLibro (lib);
i++;
}
else if (fm.mes == libros.vect[j].fecha.mes)
{
if (fm.dia >= libros.vect[j].fecha.dia)
{
cout << "Libro " << i << " : " << endl << endl;
lib = libros.vect[j];
MostrarLibro (lib);
i++;
}
}
}
else if (fM.anyo == libros.vect[j].fecha.anyo)
{
if (fM.mes <= libros.vect[j].fecha.mes)
{
cout << "Libro " << i << " : " << endl << endl;
lib = libros.vect[j];
MostrarLibro (lib);
i++;
}
else if (fM.mes == libros.vect[j].fecha.mes)
{
if (fM.dia <= libros.vect[j].fecha.dia)
{
cout << "Libro " << i << " : " << endl << endl;
lib = libros.vect[j];
MostrarLibro (lib);
i++;
}
}
}
}
return;
}
Por si alguien lo quiere ver, los struct son:
struct Fecha
{
int dia,mes,anyo;
};
struct Libro
{
Fecha fecha;
string titulo, autor;
float precio;
};
const string NOM_FICH="PracticaFinal_opcion1.libros.dat";
const int MAX=2000;
typedef Libro VecLibros[MAX];
struct Libros
{
int num;
VecLibros vect;
};
La funcion PedirFecha()
Fecha PedirFecha ()
{
Fecha fecha;
cout << " Dia: ";
cin >> fecha.dia;
cout << endl;
cout << " Mes: ";
cin >> fecha.mes;
cout << endl;
cout << " Anyo: ";
cin >> fecha.anyo;
cout << endl;
return fecha;
}
Y por ultimo la funcion MostrarLibro:
void MostrarLibro (Libro libro)
{
cout << " Titulo del libro:";
cout << libro.titulo;
cout << endl;
cout << " Nombre del autor:";
cout << libro.autor;
cout << endl;
cout << " Precio de adquisicion:";
cout << libro.precio;
cout << endl;
cout << " Dia de compra:";
cout << libro.fecha.dia;
cout << endl;
cout << " Mes de compra:";
cout << libro.fecha.mes;
cout << endl;
cout << " Anyo de compra:";
cout << libro.fecha.anyo << endl << endl;
return;
}
El primer of parece tener las condiciones al reves
Efectivamente xD. Además tenía que añadir varias condiciones más, un poco raro.