|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
求求热心的同学帮我看一下程序为什么会错以及提出修改的方法,哭了,我不知道为什么会这样错,是这样的,我们作业的题目叫做分类统计字符串中
字母数字空格其他的数量,然后我这样写,我学过C++的,这样的题再C++是简单过喝白开水的事情可是我研究了一天的Delphi都没搞明白,哭了
我是新用户,没法发图片,哭了,我把统计的步骤发过来给你们看,还有报错的地方(很多)
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
numbers,letters,spaces,others,i:integer;
begin
numbers:=0;letters:=0;spaces:=0;others:=0;
s:=edit1.Text;
for i:=1 to length(s) do
begin
if (s[i]<'9') and (s[i]>'0') then
numbers++
else if (s[i]<'z') and (s[i]>'a') then
letters++
else if (s[i]<'Z') and (s[i]>'A') then
letters++
else if s[i]=' ' then
spaces++
else
others++;
end
label6.Caption:=inttostr(letters);
label7.Caption:=inttostr(numbers);
label8.Caption:=inttostr(spaces);
label9.Caption:=inttostr(others);
end;
[错误] Unit2.pas(49): Expression expected but 'ELSE' found
[错误] Unit2.pas(51): Expression expected but 'ELSE' found
[错误] Unit2.pas(53): Expression expected but 'ELSE' found
[错误] Unit2.pas(55): Expression expected but 'ELSE' found
[错误] Unit2.pas(56): Expression expected but ';' found
[错误] Unit2.pas(58): Missing operator or semicolon
[致命错误] Project2.dpr(5): Could not compile used unit 'Unit2.pas'
我就直接指出来了哈~ 大家一起互相学习~
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
numbers,letters,spaces,others,i:integer;
begin
numbers:=0;letters:=0;spaces:=0;others:=0;
s:=edit1.Text;
for i:=1 to length(s) do
begin
if (s[i]<'9') and (s[i]>'0') then
{这(numbers++)是个错误语法格式(下面同理) ,delphi不认识,就对应了 Expression expected but 'ELSE' found(表达异常)}
numbers: =numbers+ 1;// 也可以这样写 :Inc(numbers,1) 或 Inc(numbers) ps:lnc函数使用方法 自己百度一下
{else if (s[i]<'z') and (s[i]>'a') then
letters++
else if (s[i]<'Z') and (s[i]>'A') then
letters ++ 这一部分可以下面这样写}
else if ((s[i] < 'z') and (s[i] > 'a') or (s[i] < 'Z') and (s[i] > 'A')) then
letters := letters + 1
else if s[i]=' ' then
spaces := spaces + 1
else
others := others + 1
{这个地方需要一个分号 对应这两个 Expression expected but ';' found 和 Missing operator or semicolon}
end;
label6.Caption:=inttostr(letters);
label7.Caption:=inttostr(numbers);
label8.Caption:=inttostr(spaces);
label9.Caption:=inttostr(others);
end;
{以上成功编译后 [致命错误] Project2.dpr(5): Could not compile used unit 'Unit2.pas' 就会消失}
|
|