Другие языки программирования и технологии

Помогите найти ошибку в программе и исправить ее.

Var s,s2:string; i:integer;
Begin
readln (s);
While i<=length(s) do begin
i:=i+1;
While s[i] <> ' ' do begin
if s='.-' then write('A');
if s='-...' then write('Б');
if s='.--' then write('В');
if s='--.' then write('Г');
if s='-..' then write('Д');
if s='.' then write('Е');
if s='...-' then write('Ж');
if s='--..' then write('З');
if s='..' then write('И');
if s='.---' then write('Й');
if s='-.-' then write('К');
if s='.-..' then write('Л');
if s='--' then write('М');
if s='-' then write('Н');
if s='---' then write('О');
if s='.--.' then write('П');
if s='.-.' then write('Р');
if s='...' then write('С');
if s='-' then write('Т');
if s='..-' then write('У');
if s='..-.' then write(' Ф');
if s='....' then write('Х');
if s='-.-.' then write('Ц');
if s='---.' then write('Ч');
if s='----' then write('Ш');
if s='--.-' then write('Щ');
if s='.--.-' then write('Ъ');
if s='-.--' then write('Ы');
if s='-..-' then write('Ь');
if s='..-.' then write('Э');
if s='..--' then write('Ю');
if s='.-.-' then write('Я');
s2:=s2+s[i];
i:=i+1;
End;
End;
End.
Нужно сделать так, чтобы из морзянки переводило в слово.
Помогите пожалуйста.
Var s,s2:string; i:integer;

procedure fn(s: string);
begin
if s='.-' then write('A');
if s='-...' then write('Б');
if s='.--' then write('В');
if s='--.' then write('Г');
if s='-..' then write('Д');
if s='.' then write('Е');
if s='...-' then write('Ж');
if s='--..' then write('З');
if s='..' then write('И');
if s='.---' then write('Й');
if s='-.-' then write('К');
if s='.-..' then write('Л');
if s='--' then write('М');
if s='-' then write('Н');
if s='---' then write('О');
if s='.--.' then write('П');
if s='.-.' then write('Р');
if s='...' then write('С');
if s='-' then write('Т');
if s='..-' then write('У');
if s='..-.' then write(' Ф');
if s='....' then write('Х');
if s='-.-.' then write('Ц');
if s='---.' then write('Ч');
if s='----' then write('Ш');
if s='--.-' then write('Щ');
if s='.--.-' then write('Ъ');
if s='-.--' then write('Ы');
if s='-..-' then write('Ь');
if s='..-.' then write('Э');
if s='..--' then write('Ю');
if s='.-.-' then write('Я');
end;

Begin
readln (s2);
s2:=trim(s2)+' ';
repeat
i:=i+1;
s:='';
While s2[i] <> ' ' do begin
s:=s+s2[i];
i:=i+1;
End;
fn(s);
until i>=length(s2);
End.
Александр Заболуев
Александр Заболуев
20 418
Лучший ответ
Александр Заболуев .-..- ---------- ---- .---
Александр Заболуев учитывая свойство майла жрать пробелы, основная часть проги должна выглядеть так
Begin
readln (s2);
s2:=trim(s2)+'/';
repeat
i:=i+1;
s:='';
While s2[i] in ['.','-'] do begin
s:=s+s2[i];
i:=i+1;
End;
fn(s);
until i>=length(s2);
End.
Александр Заболуев .-../..-/---./----/../.---/---/-/.--/./-
"из морзянки переводило в слово."
Тогда на входе строка должна быть. А в морзянке есть такая проблема, что '.' и '..' попробуй отличи,
то ли надо вводить через пробел, как бы на звук они отличают, что следующая буква идет, то ли еще как.
В условии задачи не задано.
Ну и
if ...
else if ...
else if ...
хоть применяйте, хотя можно и последовательно по символу case сделать.
RI
Rusya Ismailov
80 259