如何用 pascal 编写数组?

发布于 2024-10-16 20:29:36 字数 1819 浏览 2 评论 0原文

这个程序用数组正确编写吗?

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

Is this program correctly written with the array?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

丢了幸福的猪 2024-10-23 20:29:36

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

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

Looks good, but you might want to include the ; after the datatype (string)

Patient : Array[1..10] of String;
我要还你自由 2024-10-23 20:29:36

代码中存在一些问题。

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

  • 您在字符串的 Array[1..10] 之后缺少一个分号 (;)

  • 缺少某些 end; 语句。 While (Name <> 'END')Do beginFor count:= 1 to 10 Do begin 应该有一个匹配的 end; 语句。

  • 变量Tmb未声明。

  • Bloodtest 将始终为 0。它被初始化为 0,并且唯一一次写入 Bloodtest 是在这一行:BloodTest := (Num * BloodTest); 。这可能不是您想要做的。

  • 除非用户键入 类型 1类型 2,否则

    DoctorFee 不会初始化。 NMB_Payable 也有类似的问题。

  • 有一个变量Count已初始化,但之后从未使用过。不会造成任何损害,但为了可读性,我会清理它。

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

如果您解释您想要实现的目标,我们可以帮助您。

There are some problems in the code.

  • Your code was not formatted. Especially the lack of indenting makes it hard to understand what's going on. (thanks to GolezTrol for fixing that)

  • You're missing a semi-colon (;) after Array[1..10] of string

  • Some end; statement is missing. Either While (Name <> 'END')Do begin or For count:= 1 to 10 Do begin should have a matching end; statement.

  • Variable Tmb is not declared.

  • Bloodtest will always be 0. It's initialized to 0, and the only time you write to Bloodtest is on this line: BloodTest := (Num * BloodTest);. That's probably not what you want to do.

  • DoctorFee is uninitialized unless the user types Type 1 or Type 2. NMB_Payable has a similar problem.

  • There's a variable Count that's initialized, but never used afterwards. Doesn't do any damage, but for readability I'd clean it up.

To answer your question: No, you're not using the array that's declared, and I don't think this program does what you want it to do.

If you explain what you're trying to accomplish, we can help you out with that.

小女人ら 2024-10-23 20:29:36

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

它还会询问每位患者 10 次并为其开具账单。我听说过重复计费,但这太疯狂了!

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

I don't see where it's writing to the array at all, nor where it would make any use of the array in the first place. It's simply processing each item it gets, nothing is carried to be stored in an array in the first place.

It's also going to ask and bill each patient 10 times. I've heard of double-billing but this is crazy!

You should always run your code and see what actually happens. It's quite obvious you didn't.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文