1
next, I created a struct
struct eventos
{
int codigo;
char data[11];
char atracao[50];
int ingresso;
float valoring;
};
And then I created a vector that way
struct eventos ficha[5];
My goal is to verify within a function called query(), if a code provided by the user corresponds to the code of an event already registered previously (In this program, there is the possibility of registering an event and one of the categories of the record is the event code), and then, after this check, I display the event data through another function called display(). I created query() as follows:
void consulta()
{
printf("Digite o codigo do evento que deseja consultar\n ");
scanf("%d", &code);
for(h=0;h<2;h++)
{
if(code == ficha[h].codigo)
{
exibir();
system("pause");
system("cls");
}
else
{
printf("Evento nao cadastrado\n ");
system("pause");
system("cls");
}
}
}
However, a problem persists, every time I search for a code, if it is in the first positions of the vector, the event data is displayed, followed by, for example, two messages of "Event not registered". Similarly, if the code is in the last positions, it is displayed first "Event not registered", to finally display the event information corresponding to the code entered. I would like to know how to make the program break the loop as soon as it finds a valid code and display the event data. I tried to use the "break;" function, but somehow it works for the first test, but when, when registering two events, I get success consulting the first and the second is listed as an unregistered event.
If you can help me with some way out, I’d be very grateful!