Помощь - Поиск - Пользователи - Календарь
Полная версия: Угадай число
Форум «Всё о Паскале» > Pascal, Object Pascal > Задачи
compiler
вот решил написать эту программу, та както не работает...
Помогите, пожалуйста
Uses Crt;

procedure Menu;
	begin
		clrscr();
		TextColor(LightGreen);
		WriteLn;
		
		WriteLn(' УГАДАЙ ЧИСЛО'); 
		WriteLn;
		WriteLn('Сыграем?');
		WriteLn(' y: Старт');
		WriteLn;
		WriteLn(' n: Выход');
		WriteLn( #10#13, #10#13, #10#13, #10#13, #10#13);
		WriteLn(' Выбор: ');
	end;


procedure victory(j:byte);
	begin
		writeln('Поздравляем Вы победили за', j ,'попыток');
		readln;
		read;
	end;

procedure looser (RandInt:byte);
	begin
		writeln('Вы проиграли...');
		writeln('Загаданное число:' , RandInt );
		readln;
		read;
	end;


procedure BeginGame;
	var
		RandInt, UserInt, j: byte;
	const
		 MaxInt: byte =100;
		 MaxJ: byte =10;
	begin
		TextColor(LightGreen);
		RandInt:=random(MaxInt);
		for j:=1 to MaxJ do begin
			WriteLn(' Введите число');
			ReadLn(UserInt);
			case   byte((UserInt - RandInt) > 0) + 2 * byte((UserInt - RandInt) < 0) of
				0: begin victory(j); exit end;
				1: writeln('Загаданное число меньше введеного');
				2: writeln('Загаданное число больше введеного');
				
			end;					
		end;
		menu;
	end;	

procedure EndGame;
	begin
		TextColor(LightRed);
		WriteLn(' ПРИХОДИТЕ ЕЩЕ...'); 
		
	end;

function Choice:boolean;
	var
		ch: char;
	begin
		ch:='q';
		while (ch<>'y') or (ch<>'n') do begin 
			ch := ReadKey;
			case ch of
				'y':Choice:=true;
				'n':Choice:=false;
			end;
		end;
		
	end;
begin
	Menu;
	if Choice =true then 	BeginGame
		else EndGame;
end.

ЗЫ -- компилятор FP.
мисс_граффити
вот так:
function Choice:boolean;
var ch: char;
begin
ch:='q';
while (ch<>'y') and (ch<>'n') do
  ch:=ReadKey;
case ch of
'y':Choice:=true;
'n':Choice:=false;
end;
compiler
дурацкая ошибка...

мисс_граффити, спасибо..
klem4
немного короче
function Choice: Boolean;
var
  ch: char;
begin
  repeat ch := readkey until UpCase(ch) in ['Y', 'N'];
  Choice := (UpCase(ch) = 'Y');
end; 
compiler
klem4, здорово... + ставить сегодня не могу(а так бы поставил...)
compiler
собственно подредактировал (хотел зациклить, как-то не выходит) посмотрите пожалуйста..
Uses Crt;

procedure Menu;
	begin
		clrscr();
		TextColor(LightGreen);
		WriteLn;
		
		WriteLn(' УГАДАЙ ЧИСЛО'); 
		WriteLn;
		WriteLn('Сыграем?');
		WriteLn(' y: Старт');
		WriteLn;
		WriteLn(' n: Выход');
		WriteLn( #10#13, #10#13, #10#13, #10#13, #10#13);
		WriteLn(' Выбор: ');
	end;


procedure victory(j:byte);
	begin
		writeln('Поздравляем Вы победили за', j ,'попыток');
		repeat until not keypressed;
		(*Menu;*)
	end;

procedure looser (RandInt:byte);
	begin
		writeln('Вы проиграли...');
		writeln('Загаданное число:' , RandInt );
		repeat until not keypressed;
		(*Menu;*)
	end;


procedure BeginGame;
	var
		RandInt, UserInt, j: byte;
	const
		 MaxInt:	byte =100;
		 MaxJ: 	byte =10;
		 sleep:	integer =1;
	begin
		writeln(#10#13, 'Поехали!', #10#13);
		TextColor(LightGreen);
		RandInt:=random(MaxInt);
		for j:=1 to MaxJ do begin
			WriteLn(' Введите число');
			ReadLn(UserInt);
			Delay(sleep);
			case   byte((UserInt - RandInt) > 0) + 2 * byte((UserInt - RandInt) < 0) of
				0: begin victory(j); exit end;
				1: writeln('Загаданное число меньше введеного<');
				2: writeln('Загаданное число больше введеного>');
				
			end;					
		end;
		looser(RandInt);
	end;	

procedure EndGame;
	begin
		TextColor(LightRed);
		WriteLn(' ПРИХОДИТЕ ЕЩЕ...'); 
		Delay(2000);
		
	end;

function Choice: Boolean;
var
  ch: char;
begin
  repeat ch := readkey until UpCase(ch) in ['Y', 'N'];
  Choice := (UpCase(ch) = 'Y');
end;

begin
	repeat 
	Menu;
	if Choice =true then 	BeginGame
		else EndGame;
	until Choice =true;
end.


заранее благодарен.
volvo
Ты второй раз вызывать Choice не должен - достаточно сделать так:

function EndGame: boolean;
begin
  TextColor(LightRed);
  WriteLn(' ПРИХОДИТЕ ЕЩЕ...'); 
  Delay(2000);
  EndGame := true;
end;


и теперь:
const
  b: boolean = false;
begin
  repeat

    Menu;
    if Choice then BeginGame
    else b := EndGame;

  until b;
end.

compiler
по моему надо еще как-то изменить procedure victory...
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.