case dentro de case... problema
Publicado por maotuk (3 intervenciones) el 06/08/2011 06:47:15
buenas gente... la cosa es que estoy llevando mis inicios en la programacion, en el curso de programacion 1 me piden que en pascal haga un menu que trabaje en la primer opcion pilas, y en la segunda colas (esto no lo que me jode), el problema lo tengo a la hora del case, ya que en el case principal si hago lo que me plasca, entro a la opcion uno(menu pilas) y me lee la opcion correctamente, luego al finalizar el procedure me regresa al case de menu pilas,YA AQUI NO ME VUELVE A LEER LA OPCION, solo me permite el ingreso de la opcion 4 (salir).
aqui les pego el codigo... espero me ayuden y si pueden me corrijan el programa de forma que quede claro.
program menus_pila_cola;
uses crt;
type
vector = array [1..7] of string;
var frase :string;
largo, i, pos, c, contpil :integer;
opcionpri, opcionpil, opcioncol :char;
numpil, numcol :string;
pila: vector;
PROCEDURE caso_principal;FORWARD;
PROCEDURE caso_pila;FORWARD;
PROCEDURE caso_cola;FORWARD;
function centro(frase:string):integer;
begin
largo:=length(frase);
centro:=trunc((70-largo)/2);
end;
procedure marco;
begin
for i:=3 to 69 do
begin
gotoxy(i,3);
writeln('Í');
end;
for i:=3 to 69 do
begin
gotoxy(i,7);
writeln('Í');
end;
for i:=3 to 69 do
begin
gotoxy(i,20);
write('Í');
end;
for i:=3 to 69 do
begin
gotoxy(i,25);
write('Í');
end;
for i:=4 to 24 do
begin
gotoxy(3,i);
writeln('º');
end;
for i:=4 to 24 do
begin gotoxy(70,i);
writeln('º');
end;
{empiezan las especiales}
gotoxy(3,7);
write('Ì');
gotoxy(70,7);
write('¹');
gotoxy(3,20);
write('Ì');
gotoxy(70,20);
write('¹');
gotoxy(3,25);
write('È');
gotoxy(70,25);
writeln('¼');
gotoxy(3,3);
writeln('É');
gotoxy(70,3);
writeln('»');
end;
procedure ing_pil;
begin
clrscr;
marco;
if contpil=0 then
contpil:=1;
c:=5;
frase:=('PILAS');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
frase:=('INGRESE UNICAMENTE NUMEROS ENTEROS');
pos:=centro(frase);
gotoxy(pos,23);
write(frase);
if contpil > 7 then
writeln('pila llena')
else
begin
c:=8;
frase:=('INGRESE NUMERO A LA PILA: ');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
read(numpil);
pila[contpil]:= numpil;
contpil:=contpil+1;
end;
caso_pila;
end;
procedure borra_pil;
begin
clrscr;
marco;
if pila[contpil-1]='' then
contpil:=0;
if contpil = 0 then
writeln('pila vacia')
else
begin
contpil:=contpil-1;
pila[contpil]:='';
if contpil<0 then
contpil:=0;
end;
caso_pila;
end;
procedure ing_col;
begin
clrscr;
marco;
c:=5;
frase:=('COLAS');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
frase:=('INGRESE UNICAMENTE NUMEROS ENTEROS');
pos:=centro(frase);
gotoxy(pos,23);
write(frase);
c:=8;
frase:=('INGRESE NUMERO A LA COLA: ');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
read(numpil);
caso_cola;
end;
procedure pant_principal;
begin
clrscr;
marco;
frase:= (' Menu Principal');
pos:=centro(frase);
gotoxy(pos,5);
writeln(frase);
frase:= ('1. Menu Pila.');
pos:=centro(frase);
gotoxy(pos,10);
writeln(frase);
frase:= ('2. Menu Cola.');
pos:=centro(frase);
gotoxy(pos,14);
writeln(frase);
frase:= ('3. Cerrar Programa. ');
pos:=centro(frase);
gotoxy(pos,17);
writeln(frase);
frase:= (' <Elija una opcion> ');
pos:=centro(frase);
gotoxy(pos,22);
write(frase);
readkey;
end;
procedure pant_pilas;
begin
clrscr;
marco;
frase:= (' Menu Pilas');
pos:=centro(frase);
gotoxy(pos,5);
writeln(frase);
frase:= ('1. Ingresar.');
pos:=centro(frase);
gotoxy(pos,9);
writeln(frase);
frase:= ('2. Borrar.');
pos:=centro(frase);
gotoxy(pos,11);
writeln(frase);
frase:= ('3. Mostrar ');
pos:=centro(frase);
gotoxy(pos,13);
writeln(frase);
frase:= ('4. Salir. ');
pos:=centro(frase);
gotoxy(pos,15);
writeln(frase);
frase:= (' <Elija una opcion> ');
pos:=centro(frase);
gotoxy(pos,22);
writeln(frase);
end;
procedure pant_colas;
begin
clrscr;
marco;
frase:= (' Menu colas');
pos:=centro(frase);
gotoxy(pos,5);
writeln(frase);
frase:= ('1. Ingresar.');
pos:=centro(frase);
gotoxy(pos,9);
writeln(frase);
frase:= ('2. Borrar.');
pos:=centro(frase);
gotoxy(pos,11);
writeln(frase);
frase:= ('3. Mostrar ');
pos:=centro(frase);
gotoxy(pos,13);
writeln(frase);
frase:= ('4. Salir. ');
pos:=centro(frase);
gotoxy(pos,15);
writeln(frase);
frase:= (' <Elija una opcion> ');
pos:=centro(frase);
gotoxy(pos,22);
writeln(frase);
end;
procedure caso_principal;
begin
pant_principal;
opcionpri:=' ';
while (opcionpri<>'3') do
begin
repeat
opcionpri:=readkey;
until opcionpri in['1','2','3'];
case opcionpri of
'1': begin
caso_pila;
readkey;
end;
'2': begin
caso_cola;
readkey;
end;
'3': begin
clrscr;
end;
end;{case}
end;{while}
end;
procedure caso_pila;
begin
pant_pilas;
opcionpil:=' ';
while (opcionpil<>'4') do
begin
repeat
opcionpil:=readkey;
until opcionpil in['1','2','3','4'];
case opcionpil of
'1': begin
ing_pil;
end;
'2': begin
borra_pil;
end;
'3': begin
readkey;
end;
'4': begin
caso_principal;
end;
end;{case}
end;{while}
end;
procedure caso_cola;
begin
pant_colas;
opcioncol:=' ';
while (opcioncol<>'4') do
begin
repeat
opcioncol:=readkey;
until opcioncol in['1','2','3','4'];
case opcioncol of
'1': begin
ing_col;
readkey;
end;
'2': begin
readkey;
end;
'3': begin
readkey;
end;
'4': begin
caso_principal;
end;
end;{case}
end;{while}
end;
begin
clrscr;
caso_principal;
readkey;
end.
aqui les pego el codigo... espero me ayuden y si pueden me corrijan el programa de forma que quede claro.
program menus_pila_cola;
uses crt;
type
vector = array [1..7] of string;
var frase :string;
largo, i, pos, c, contpil :integer;
opcionpri, opcionpil, opcioncol :char;
numpil, numcol :string;
pila: vector;
PROCEDURE caso_principal;FORWARD;
PROCEDURE caso_pila;FORWARD;
PROCEDURE caso_cola;FORWARD;
function centro(frase:string):integer;
begin
largo:=length(frase);
centro:=trunc((70-largo)/2);
end;
procedure marco;
begin
for i:=3 to 69 do
begin
gotoxy(i,3);
writeln('Í');
end;
for i:=3 to 69 do
begin
gotoxy(i,7);
writeln('Í');
end;
for i:=3 to 69 do
begin
gotoxy(i,20);
write('Í');
end;
for i:=3 to 69 do
begin
gotoxy(i,25);
write('Í');
end;
for i:=4 to 24 do
begin
gotoxy(3,i);
writeln('º');
end;
for i:=4 to 24 do
begin gotoxy(70,i);
writeln('º');
end;
{empiezan las especiales}
gotoxy(3,7);
write('Ì');
gotoxy(70,7);
write('¹');
gotoxy(3,20);
write('Ì');
gotoxy(70,20);
write('¹');
gotoxy(3,25);
write('È');
gotoxy(70,25);
writeln('¼');
gotoxy(3,3);
writeln('É');
gotoxy(70,3);
writeln('»');
end;
procedure ing_pil;
begin
clrscr;
marco;
if contpil=0 then
contpil:=1;
c:=5;
frase:=('PILAS');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
frase:=('INGRESE UNICAMENTE NUMEROS ENTEROS');
pos:=centro(frase);
gotoxy(pos,23);
write(frase);
if contpil > 7 then
writeln('pila llena')
else
begin
c:=8;
frase:=('INGRESE NUMERO A LA PILA: ');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
read(numpil);
pila[contpil]:= numpil;
contpil:=contpil+1;
end;
caso_pila;
end;
procedure borra_pil;
begin
clrscr;
marco;
if pila[contpil-1]='' then
contpil:=0;
if contpil = 0 then
writeln('pila vacia')
else
begin
contpil:=contpil-1;
pila[contpil]:='';
if contpil<0 then
contpil:=0;
end;
caso_pila;
end;
procedure ing_col;
begin
clrscr;
marco;
c:=5;
frase:=('COLAS');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
frase:=('INGRESE UNICAMENTE NUMEROS ENTEROS');
pos:=centro(frase);
gotoxy(pos,23);
write(frase);
c:=8;
frase:=('INGRESE NUMERO A LA COLA: ');
pos:=centro(frase);
gotoxy(pos,c);
write(frase);
read(numpil);
caso_cola;
end;
procedure pant_principal;
begin
clrscr;
marco;
frase:= (' Menu Principal');
pos:=centro(frase);
gotoxy(pos,5);
writeln(frase);
frase:= ('1. Menu Pila.');
pos:=centro(frase);
gotoxy(pos,10);
writeln(frase);
frase:= ('2. Menu Cola.');
pos:=centro(frase);
gotoxy(pos,14);
writeln(frase);
frase:= ('3. Cerrar Programa. ');
pos:=centro(frase);
gotoxy(pos,17);
writeln(frase);
frase:= (' <Elija una opcion> ');
pos:=centro(frase);
gotoxy(pos,22);
write(frase);
readkey;
end;
procedure pant_pilas;
begin
clrscr;
marco;
frase:= (' Menu Pilas');
pos:=centro(frase);
gotoxy(pos,5);
writeln(frase);
frase:= ('1. Ingresar.');
pos:=centro(frase);
gotoxy(pos,9);
writeln(frase);
frase:= ('2. Borrar.');
pos:=centro(frase);
gotoxy(pos,11);
writeln(frase);
frase:= ('3. Mostrar ');
pos:=centro(frase);
gotoxy(pos,13);
writeln(frase);
frase:= ('4. Salir. ');
pos:=centro(frase);
gotoxy(pos,15);
writeln(frase);
frase:= (' <Elija una opcion> ');
pos:=centro(frase);
gotoxy(pos,22);
writeln(frase);
end;
procedure pant_colas;
begin
clrscr;
marco;
frase:= (' Menu colas');
pos:=centro(frase);
gotoxy(pos,5);
writeln(frase);
frase:= ('1. Ingresar.');
pos:=centro(frase);
gotoxy(pos,9);
writeln(frase);
frase:= ('2. Borrar.');
pos:=centro(frase);
gotoxy(pos,11);
writeln(frase);
frase:= ('3. Mostrar ');
pos:=centro(frase);
gotoxy(pos,13);
writeln(frase);
frase:= ('4. Salir. ');
pos:=centro(frase);
gotoxy(pos,15);
writeln(frase);
frase:= (' <Elija una opcion> ');
pos:=centro(frase);
gotoxy(pos,22);
writeln(frase);
end;
procedure caso_principal;
begin
pant_principal;
opcionpri:=' ';
while (opcionpri<>'3') do
begin
repeat
opcionpri:=readkey;
until opcionpri in['1','2','3'];
case opcionpri of
'1': begin
caso_pila;
readkey;
end;
'2': begin
caso_cola;
readkey;
end;
'3': begin
clrscr;
end;
end;{case}
end;{while}
end;
procedure caso_pila;
begin
pant_pilas;
opcionpil:=' ';
while (opcionpil<>'4') do
begin
repeat
opcionpil:=readkey;
until opcionpil in['1','2','3','4'];
case opcionpil of
'1': begin
ing_pil;
end;
'2': begin
borra_pil;
end;
'3': begin
readkey;
end;
'4': begin
caso_principal;
end;
end;{case}
end;{while}
end;
procedure caso_cola;
begin
pant_colas;
opcioncol:=' ';
while (opcioncol<>'4') do
begin
repeat
opcioncol:=readkey;
until opcioncol in['1','2','3','4'];
case opcioncol of
'1': begin
ing_col;
readkey;
end;
'2': begin
readkey;
end;
'3': begin
readkey;
end;
'4': begin
caso_principal;
end;
end;{case}
end;{while}
end;
begin
clrscr;
caso_principal;
readkey;
end.
Valora esta pregunta


0