I am trying to generate a method in which the user can perform an action by pressing a number (In this case, it would be to pass the supposed policy of a client from True to False). However, when I invoke it in the menu, the console tells me the error.
error: 'polizaEnMemoria' was not declared in this scope|
So I wonder, do I have to pass the vector as a parameter? If you have any additional material I would be very grateful. The codes.
The menu procedure:
char menu(void)
{
char opcion;
cout <<"Polizas en memoria.\n\nSelecciones una opcion: "<< endl;
cout <<"1 - Cargar una nueva poliza" << endl;
cout <<"2 - Desactivar una poliza existente" << endl;
cout <<"3 - Buscar por numero de poliza" << endl;
cout <<"4 - Buscar por numero de DNI" << endl;
cout <<"5 - Listar polizas activas ordenadas por incidentes descendetemente" << endl;
cout <<"6 - Procesar incidentes" << endl;
cout <<"7 - Sobreescribir archivo y salir" << endl;
cout <<"8 - Crear incidente" << endl;
cout <<"Esc - Salir" << endl;
do
opcion = getch();
while ( (opcion < 49 || opcion > 57) && opcion != 27 );
switch(opcion)
{
case '1':
cout << 1;
break;
case '2':
desactivarPoliza(polizaEnMemoria,TAMANO);
break;
case '3':
cout << 3;
break;
case '4':
cout << 4;
break;
case '5':
cout << 5;
break;
case '6':
cout << 6;
break;
case '7':
cout << 7;
break;
case '8':
cout << 8;
break;
}
return opcion;
}
The main from where I invoke the menu procedure:
int main()
{
poliza polizaEnMemoria[TAMANO];
levantarAsegurados(polizaEnMemoria, TAMANO);
char opcion;
do
opcion = menu();
while(opcion != 27);
return 0;
}
The policy deactivation procedure
void desactivarPoliza ( poliza V[],int tam)
{
int i = 0;
int PolizaADesactivar;
cout << "Ingrese numero de poliza que desea desactivar" << endl;
cin >> PolizaADesactivar;
bool encontrado = false;
while (i < tam && V[i].nroPoliza!=999999)
{
if (V[i].nroPoliza == PolizaADesactivar)
{
if (V[i].polizaActiva == 'f')
{
cout << "La poliza ya se encontraba desactivada" << endl;
getch();
}
if (V[i].polizaActiva == 'F')
{
cout << "La poliza ya se encontraba desactivada" << endl;
getch();
}
V[i].polizaActiva = 'F';
encontrado = true;
cout << "La poliza se desactivo correctamente" << endl;
getch();
}
i++;
}
if (encontrado == false)
{
cout << "No existe esa poliza" << endl;
getch();
return;
}
}
One last more general question I have is, is it preferable to create a menu procedure or code it in main?
According to this code snippet:
polizaEnMemoria
is a local variable that exists only inmain
. However in the functionmenu
you are doing the following:In this last function there is no variable to be called
polizaEnMemoria
and hence the compiler complaints.Solving the error is as simple as passing the array to the function
menu()
:It is always preferable to divide the program into small and manageable logical chunks. Its benefits are immense in the face of a small number of buts .
some windows
drawbacks