2011-02-09 40 views
0

該程序是否正確寫入數組?如何在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 
+1

我冒昧地突出你的代碼。你可以使用`{}`按鈕來做到這一點。 – GolezTrol 2011-02-09 23:59:11

+1

看起來是這樣。你嘗試編譯它嗎?另外,請稍微清理一下,有很多簡單的圓括號,並且沒有內部縮進。 – Christian 2011-02-09 23:59:26

回答

2

看起來不錯,但你可能要包括的數據類型(string

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

有在代碼中的一些問題後;

  • 您的代碼沒有格式化。特別是缺少縮進使得很難理解正在發生的事情。 (;)後Array[1..10] of string

  • 一些end;語句丟失

  • 你缺少一個分號(感謝GolezTrol用於固定)。 While (Name <> 'END')Do beginFor count:= 1 to 10 Do begin應該有匹配的end;聲明。

  • 變量Tmb未聲明。

  • 血液測試將始終爲0.它已初始化爲0,並且唯一一次您寫入Bloodtest的行是:BloodTest := (Num * BloodTest);。這可能不是你想要做的。

  • DoctorFee未初始化,除非用戶鍵入Type 1Type 2NMB_Payable也有類似的問題。

  • 有一個變量Count是已初始化,但後來從來沒有使用過。不會造成任何損害,但爲了可讀性,我會清理它。

要回答你的問題:不,你沒有使用聲明的數組,我不認爲這個程序做你想做的事。

如果你解釋你要完成什麼,我們可以幫你出這一點。

1

我沒有看到它在所有寫入到陣列中,也沒有哪裏會做擺在首位的任何使用數組。它只是處理它得到的每個項目,沒有任何東西被首先存儲在數組中。

它也要去問及法案每位患者的10倍。我聽說過雙重結算,但這太瘋狂了!

您應該始終運行代碼,看看到底發生了什麼。這很明顯,你沒有。