Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > Delphi программирование > Паскаль, Turbo Pascal, PascalABC.NET
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 19.06.2019, 17:50   #1
Chelovekk
Новичок
Джуниор
 
Регистрация: 19.06.2019
Сообщений: 1
Вопрос Прошу помочь с одной ошибкой в программе

Вот прога
Код:
var
 mesto,vmesto,hod:string;
 i,o,p,pobeda,por,obj,sm,sm1:integer; 
begin
 writeln('|================|');
 writeln('|   п -  к  - кв |'); 
 writeln('|   |    |       |');
 writeln('|   |            |');
 writeln('|   г-  - з      |');
 writeln('|        |       |');
 writeln('|                |');
 writeln('|   с  - т       |');
 writeln('|================|');
 writeln('п-прихожая(pr), г-гостиная(g), з-зал(z), с-столовая(s), т-туалет(t), к-кухня(k)');
 writeln('так, вы в прихожей, тут в кв появляется виталик, ваша цель идти в туалет, потом все объясню');
 vmesto:='kv';
 mesto:='pr';
 obj:=1;
 while (pobeda<>1) or (por<>1) do begin
 if mesto='pr' then writeln('в кухню или в гостиную');
 if mesto='g' then writeln('в зал или в прихожую');
 if mesto='k' then writeln('в кв или в зал');
 if mesto='z' then writeln('в гостиную в кухню или в туалет');
 if mesto='t' then writeln('в столовую или в зал');
 if mesto='s' then writeln('в туалет');
 if (mesto='t') and (obj=1) then writeln('ок, вы просрались, теперь в гостиную за первым ключом');
 if (mesto='t') and (obj=1) then obj:=2;
 if (mesto='g') and (obj=2) then writeln('ок, второй ключ в столовой');
 if (mesto='g') and (obj=2) then obj:=3;
 if (mesto='s') and (obj=3) then writeln('фух...всё в кв и беги');
 if (mesto='s') and (obj=3) then pobeda:=1;
 readln(hod);
 i:=random(2);
 o:=random(1);
 p:=random(0);
 sm:=random(1);
 sm1:=random(1);
 if vmesto='kv' then vmesto:='k';
 if vmesto='k' then begin
  if i=1 then vmesto:='pr';
  if i=0 then vmesto:='z';
  if i=2 then vmesto:='kv';
 end;
 if vmesto='pr' then begin
  if o=1 then vmesto:='k';
  if o=0 then vmesto:='g';
 end;
 if vmesto='g' then begin
  if o=1 then vmesto:='pr';
  if o=0 then vmesto:='z';
 end;
 if vmesto='z' then begin
  if i=0 then vmesto:='k';
  if i=1 then vmesto:='g';
  if i=2 then vmesto:='t';
 end;
 if vmesto='t' then begin
  if o=1 then vmesto:='s';
  if o=0 then vmesto:='z';
 end;
 if vmesto='s' then vmesto:='t';
 if (mesto='kv') and (hod='k') then mesto:='k';
 if (mesto='k') and (hod='kv') then mesto:='kv';
 if (mesto='k') and (hod='pr') then mesto:='pr';
 if (mesto='k') and (hod='z') then mesto:='z';
 if (mesto='s') and (hod='t') then mesto:='t';
 if (mesto='t') and (hod='s') then mesto:='s';
 if (mesto='t') and (hod='z') then mesto:='z';
 if (mesto='pr') and (hod='k') then mesto:='k';
 if (mesto='pr') and (hod='g') then mesto:='g';
 if (mesto='z') and (hod='k') then mesto:='k';
 if (mesto='z') and (hod='t') then mesto:='t';
 if (mesto='z') and (hod='g') then mesto:='g';
 if (mesto='g') and (hod='pr') then mesto:='pr';
 if (mesto='g') and (hod='z') then mesto:='z';
 if (mesto=vmesto) and (mesto='g' or 'kv' or 'z' or 's') then if sm=sm1 then por:=1 else writeln('фух...он вас не заметил');
 if (mesto=vmesto) and (mesto='t' or 'k' or 'pr') then por:=1;
end;
if pobeda=1 then write('ты победил') else write('к сожалению или к счастью вас убили');
end.
При вводе g(гостиная) во время хода(идти в гостиную)
Выдаёт unspecified error и вылетает, всё остальное работает отлично



_____
Код программы нужно выделять (форматировать) тегами [CODE] [/CODE] (читать FAQ)
Модератор

Последний раз редактировалось Serge_Bliznykov; 19.06.2019 в 20:43.
Chelovekk вне форума Ответить с цитированием
Старый 19.06.2019, 20:52   #2
Serge_Bliznykov
Старожил
 
Регистрация: 09.01.2008
Сообщений: 26,238
По умолчанию

Цитата:
Сообщение от Chelovekk Посмотреть сообщение
При вводе g(гостиная) во время хода(идти в гостиную)
очень странно.
Ваш код вообще не должен был компилироваться!
У Вас какой паскаль? Небось какой-нибудь PascalABC или PascalABC.NET ?

Цитата:
Код:
 if (mesto=vmesto) and (mesto='g' or 'kv' or 'z' or 's') then if sm=sm1 then por:=1 else writeln('фух...он вас не заметил');
 if (mesto=vmesto) and (mesto='t' or 'k' or 'pr') then por:=1;
так нельзя писать.
можно так:
Код:
 if (mesto=vmesto) and ((mesto='g') or (mesto='kv') or (mesto='z') or (mesto='s')) then if sm=sm1 then por:=1 else writeln('фух...он вас не заметил');
 if (mesto=vmesto) and ((mesto='t') or (mesto='k') or (mesto='pr')) then por:=1;
ну и по хорошему переменные надо иницилизировать перед использованием:
Цитата:
Код:
Compiling gm.pas
gm.pas(21,9) Warning: Variable "pobeda" does not seem to be initialized
gm.pas(21,24) Warning: Variable "por" does not seem to be initialized
gm.pas(3,6) Note: Local variable "p" is assigned but never used
Serge_Bliznykov вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Прошу помочь разобраться с ошибкой IDE FreePascal tovit Lazarus, Free Pascal, CodeTyphon 4 12.04.2018 01:52
Прошу помочь понять одну строку в программе Студ Общие вопросы C/C++ 3 11.04.2014 14:06
Прошу помочь найти ошибку в программе shymaxer1 Общие вопросы C/C++ 0 27.03.2014 23:19
Алгоритмы. Не прошу решить. Прошу помочь! pascaluser Паскаль, Turbo Pascal, PascalABC.NET 2 12.10.2012 08:45