问题1:
编写一个做算术题的程序,程序的设计界面如图3-3所示。程序执行时,单击【出题】按钮,将随机产生100以内的非负加数和被加数,当在等号“=”右边的方框里写出正确答案后,单击【结果】按钮,将显示“答案正确”;如果输入的答案不正确,将显示“答案错误”。
那个随机产生的数怎么做啊????
问题2:
正切函数怎么使用阿,我想实现输入一个数,单击按钮后,输出正切值

解决方案 »

  1.   

    Random函数返回一个大于等于零小于一的随机数,
    下面是Delphi中的例子
    var
       I: Integer;
     begin
       Randomize;
       for I := 1 to 50 do begin
         { Write to window at random locations }
         Canvas.TextOut(Random(Width), Random(Height), 'Boo!');
       end;
     end;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject); //出题
    var
      i: integer;
    begin
      Randomize;
      for i:=0 to 100 do
      begin
        Edit1.Text := IntToStr(Random(i));
        Edit2.Text := IntToStr(Random(i));
      end;
    end;procedure TForm1.Button1Click(Sender: TObject); //查看结果
    begin
      if (StrToInt(Edit1.Text)+StrToInt(Edit2.Text)=StrToInt(Edit3.Text)) then
        ShowMessage('正确')
      else
        ShowMessage('错误');
    end;至于正切,你直接用tan函数啊,Uses Math
      

  3.   

    麻烦问一下楼上大虾,如果我用一个radom(i),那么是返回i左右的一个数么,另外,随机数的出现符合什么样的分布呢?谢谢
      

  4.   

    radom(i)不是返回i左右的啊,是说随机取一个i,至于i的范围是前面的for循环确定的
      

  5.   

    random(i)是随机返回一个0~i-1的整数,至于符合什么分布就不得而知了。
      

  6.   

    procedure TForm1.Button1Click(Sender: TObject); //出题
    var
      i: integer;
    begin
      Randomize;
      Edit1.Text := IntToStr(Random(i));
      Edit2.Text := IntToStr(Random(i));
      end;
    end;procedure TForm1.Button2Click(Sender: TObject); //查看结果
    begin
      if (StrToIntDef(Edit1.Text, 0)+StrToIntDef(Edit2.Text, 0)=StrToIntDef(Edit3.Text, 0)) then
        ShowMessage('正确')
      else
        ShowMessage('错误');
    end;