鱼C论坛

 找回密码
 立即注册
查看: 1736|回复: 2

[已解决]求求热心的同学帮我看一下程序为什么会错以及提出修改的方法

[复制链接]
发表于 2020-3-24 21:25:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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'
最佳答案
2020-3-27 11:57:18
我就直接指出来了哈~ 大家一起互相学习~
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<'9') and (s>'0') then
{这(numbers++)是个错误语法格式(下面同理) ,delphi不认识,就对应了 Expression expected but 'ELSE' found(表达异常)}
        numbers: =numbers+ 1;// 也可以这样写 :Inc(numbers,1)  或 Inc(numbers)  ps:lnc函数使用方法 自己百度一下
      {else if (s<'z') and (s>'a') then
        letters++
      else if (s<'Z') and (s>'A') then
        letters ++    这一部分可以下面这样写}

      else if ((s < 'z') and (s > 'a') or (s < 'Z') and (s > 'A')) then
      letters := letters + 1
      else if s=' '  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' 就会消失}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2020-3-24 21:33:57 | 显示全部楼层
是不是你if后面都没加分号(没学过delphi我猜的)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-3-27 11:57:18 | 显示全部楼层    本楼为最佳答案   
我就直接指出来了哈~ 大家一起互相学习~
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<'9') and (s>'0') then
{这(numbers++)是个错误语法格式(下面同理) ,delphi不认识,就对应了 Expression expected but 'ELSE' found(表达异常)}
        numbers: =numbers+ 1;// 也可以这样写 :Inc(numbers,1)  或 Inc(numbers)  ps:lnc函数使用方法 自己百度一下
      {else if (s<'z') and (s>'a') then
        letters++
      else if (s<'Z') and (s>'A') then
        letters ++    这一部分可以下面这样写}

      else if ((s < 'z') and (s > 'a') or (s < 'Z') and (s > 'A')) then
      letters := letters + 1
      else if s=' '  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' 就会消失}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-27 04:03

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表