Your function as written does not make much sense:
- You store the name of the event in
d
(could not it be better called nombreEvento
or evento
?)
- Since there are no loops in the function, it is expected that the program will have to call the function several times
-
d
is not static, then the value entered in the first call will not be available in the second one
- Neither do you enable any mechanism so that the value of said variable leaves the function or can be passed from outside (neither return nor arguments).
- What is
valorBase
? Your declaration has been omitted in the code.
- How does data entry work?
- The output chains do not have line breaks Have you tried the code at some time?
- The
switch
options are not separated by a break
. Have you forgotten?
We go in parts.
If the function does not have to be called several times, then you need a loop in the function:
void evento()
{
int opcion;
do
{
cout << "BIENVENIDO\n"
<< "1-Crear un evento\n"
<< "2-Ingresar datos a evento nuevo\n"
<< "3-Salir\n";
switch (opcion)
{
// ...
}
} while( opcion != 3 );
}
If it turns out that it does not, that it has to be called several times then the logical thing is that it receives via arguments the data that it needs to work. In any case (and this also applies to the previous example) you should indicate what happens if the user enters a value outside the range (1,2)
void evento(char* nombreEvento, /* ... */)
{
int opcion;
cout << "BIENVENIDO\n"
<< "1-Crear un evento\n"
<< "2-Ingresar datos a evento nuevo\n";
switch (opcion)
{
// ...
case default:
/* ¿Qué hacer aquí? */
}
}
If it turns out that the function has to be self-contained and it will be called several times (I can not think of the reason, but seeing the status of the code can not be guessed too much), then d
should be static to keep its Value between different calls:
void NuevoEvento(char* evento, char* valor)
{
cout << "Usted va a crear un nuevo evento\n"
<< "Por favor,indique el nombre del evento a crear";
cin >> ptr;
cout << "Por favor, digite el valor de la boleta base (Sin comas ni puntos)";
cin >> valor;
cout << "Evento creado con exito";
}
void evento(){
int opcion;
static char d[10000] = 'void evento()
{
int opcion;
do
{
cout << "BIENVENIDO\n"
<< "1-Crear un evento\n"
<< "2-Ingresar datos a evento nuevo\n"
<< "3-Salir\n";
switch (opcion)
{
// ...
}
} while( opcion != 3 );
}
';
cout<<"BIENVENIDO";
cout<<"1-Crear un evento";
cout<<"2-Ingresar datos a evento nuevo";
switch (opcion){
case 1:
NuevoEvento(d,valorBase);
break; // ¿Seguro que no es necesario?
case 2:
if( *d == 0 )
cout << "Primero debes crear el evento\n";
else
IntroducirDatosEvento(d);
break;
}
}
I have taken the trouble to get the code out of the function by simple readability. The switch
can already be too problematic to tempt the devil.