如何在pascal中编写数组?

时间:2011-02-09 23:57:23

标签: arrays pascal

这个程序是否正确写入了数组?

Program Malaria_Outbreak (input,output);

Var
   BC:real;
   LO:real;
   count:integer;
   Num:integer;
   BloodTest:integer;
   Registration:integer;
   Clinic:string;
   DoctorFee:integer;
   Total:integer;
   NMB_Payable:real;
   Company:string;
   Name:string;
   Patient:Array[1..10] of string

Begin
   clrscr;
   BC:=(0.8);
   LO:=(0.7);
   Count:=(0);
   Num:=(0);
   BloodTest:=(Num * 700);
   Registration:=(500);
   Writeln('Please enter the name of the patient');
   Readln(Name);
   While (Name <> 'END')Do
     Begin
       For count:= 1 to 10 Do
         Begin
           Writeln('Please enter the clinic the patient attends');
           Readln(Clinic);
           If (Clinic = 'Type 1') Then
             Begin
               DoctorFee:=(800);
             End;
           If (Clinic = 'Type 2') Then
             Begin
               DoctorFee:=(1200);
             End;
           Writeln('The doctor fee for the patient is $',DoctorFee);
           Writeln('Please enter the number of blood tests the patient has had');
           Readln(Num);
           BloodTest:=(Num * BloodTest);
           Writeln('The blood test for the patient is $',BloodTest);
           TMB:=(Registration + DoctorFee + BloodTest);
           Writeln('The total medical bill for the patient is $',TMB);
           Writeln('Please enter the insurance company the clinic is affiliated with');
           Readln(Company);
           If (Company = 'Blue Cross') Then
             Begin
               NMB_Payable:=(BC * TMB);
             End;
           If (Company = 'LOJ') Then
             Begin
               NMB_Payable:=(LO * TMB);
             End;
           Writeln('The net medical bill for the patient is $',NMB_Payable);
       End;
   Readln;
   Readln;
End

3 个答案:

答案 0 :(得分:2)

看起来不错,但您可能希望在数据类型(;)之后包含string

Patient : Array[1..10] of String;

答案 1 :(得分:2)

代码中存在一些问题。

  • 您的代码未格式化。特别是缺乏缩进使得很难理解发生了什么。 (感谢GolezTrol修复它)

  • 您在Array[1..10] of string

  • 之后错过了分号(;)
  • 缺少某些end;语句。 While (Name <> 'END')Do beginFor count:= 1 to 10 Do begin应该有匹配的end;声明。

  • 未声明变量Tmb

  • Bloodtest将始终为0.它已初始化为0,并且您写入Bloodtest的唯一时间就在此行:BloodTest := (Num * BloodTest);。那可能不是你想要做的。

  • 除非用户键入DoctorFeeType 1,否则
  • Type 2未初始化。 NMB_Payable也有类似的问题。

  • 有一个变量Count已初始化,但之后从未使用过。不会造成任何损害,但为了便于阅读,我会将其清理干净。

回答你的问题:不,你没有使用声明的数组,我不认为这个程序能做你想做的事。

如果你解释一下你想要完成什么,我们可以帮助你解决这个问题。

答案 2 :(得分:1)

我根本没有看到它写入数组的位置,也没有看到它首先使用数组的位置。它只是处理它获得的每个项目,首先不会将任何内容存储在数组中。

它还会向每位患者询问并开具10次费用。我听说过双重计费,但这太疯狂了!

您应始终运行代码并查看实际发生的情况。很明显你没有。

相关问题