如何用 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
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来不错,但您可能需要在数据类型 (
string
) 之后包含;
Looks good, but you might want to include the
;
after the datatype (string
)代码中存在一些问题。
您的代码未格式化。特别是缺乏缩进使得很难理解发生了什么。 (感谢 GolezTrol 修复了这个问题)
您在字符串的
Array[1..10] 之后缺少一个分号 (;)
缺少某些
end;
语句。While (Name <> 'END')Do begin
或For 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. EitherWhile (Name <> 'END')Do begin
orFor count:= 1 to 10 Do begin
should have a matchingend;
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 typesType 1
orType 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.
我根本看不到它在哪里写入数组,也看不到它首先会在哪里使用数组。它只是处理它获得的每个项目,首先没有任何内容存储在数组中。
它还会询问每位患者 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.