2017-03-02 3 views
-3
PROGRAM approvedapplicants(input,output); 
uses crt; 
var 
applcntname,housingcomm,clarendon_court,providence_gardens, 
sangre_grande_villas:string; 
slry,spcslry:integer; 
c_qual_sal,s_qual_sal,p_qual_sal,qualifying_salary:integer; 

BEGIN 
writeln('enter applicant name, salary, spouce salary'); 
readln(applcntname,slry,spcslry); 
writeln('enter housing community'); 
readln(housingcomm); 
BEGIN 
qualifying_salary:=0; 
IF(housingcomm=clarendon_court) 
then 
qualifying_salary:=$12500; 
writeln('you have selected clarendon court!'); 
readln(c_qual_sal) ; 
end if ; 

    else if(housingcomm=sangre_grande_villas)then 
    qualifying_salary:=$9500; 
    writeln('you have selected sangre grande villas!'); 
    readln(s_qual_sal); 
    end if ; 

    else(housingcomm=providence_gardens)then; 
    qualifying_salary:=$7500; 
    writeln('you have selected providence gardens!'); 
    readln(p_qual_sal); 
    end if; 
    END. 
+1

if then、[if then else](http://www.freepascal.org/docs-html/3.0.0/ref/refsu58.html)の構造を知る必要があります。あなたのコードに 'if'や'; 'をあまりにも多く持っていて、' begin'のいくつかが欠けています。 –

+0

@DavidAによると、パスカルには 'end if'のようなものはありません。 –

+1

あなたは本当にパスカル文法を学ぶ必要があります - あなたのコードは間違いや多分誤解で詰まっています.. 'end if'構造を持っていません - ' end'は通常 'begin'と一緒です(例外はありますが' if' isn 1人1人)。 'else xxx then'はなく、' then'の後ろにセミコロンが続くことは何もしません。 – MartynA

答えて

4

通常は、私たちは宿題/授業への回答を投稿しませんが、このコードではあなたのコードは非常に広いので、この場合は例外を出しても問題ありません。

私は私はあなたが意図していると思うものをほとんどありませんし、私はそれについていくつかのことを説明しますと思われ、このプログラムをコンパイルして実行してみてください:

program approvedapplicants(input,output); 
uses crt; 

var 
    ApplicantName, 
    HousingCommunity, 
    ClarendonCourt, 
    ProvidenceGardens, 
    SangreGrandVillas :string; 
    Salary, 
    SpouseSalary, 
    QualifyingSalary : Integer; 
    CQualSal, 
    PQualSal, 
    SQualSal : Integer; 
    slry,spcslry:integer; 

begin 
    ClarendonCourt := 'Clarendon Court'; 
    ProvidenceGardens := 'Providence Gardens'; 
    SangreGrandVillas := 'Sangre Grand Villas'; 
    QualifyingSalary := 0; 

    writeln('enter applicant name'); 
    readln(ApplicantName); 

    writeln('enter salary'); 
    readln(Salary); 

    writeln('enter spouse salary'); 
    readln(SpouseSalary); 

    writeln('enter housing community'); 
    readln(HousingCommunity); 

    if (HousingCommunity = ClarendonCourt) then begin 
    QualifyingSalary := $12500; 
    writeln('you have selected clarendon court!'); 
    readln(CQualSal); 
    end 
    else 
    if(HousingCommunity = SangreGrandVillas)then begin 
     QualifyingSalary := $9500; 
     writeln('you have selected sangre grande villas!'); 
     readln(SQualSal); 
    end 
    else 
    if HousingCommunity = ProvidenceGardens then begin 
     QualifyingSalary :=$7500; 
     writeln('you have selected providence gardens!'); 
     readln(CQualSal); 
    end; 

end. 

まず、それがどのようにはるかに簡単に気づきますその論理を読み、従う。これは主に ため

  • コードの論理 構造を反映している(インデントブロックを含む)のレイアウトの使用です。

  • programbeginendなどのキーワードの一貫性のある、下部ケースの使用など キーワードは、通常、ソースコードの最も興味深い内容であり、彼らがあなたに叫ん持つこと 邪魔です。

  • 任意に「申請者」の「I」 と第二の「a」のような変数名(から文字を落とすの回避は。遅いマシン上で実行されていると解釈コードの時代には、このためのいくつかの正当化はargubably がありました、ではなく、より多くの芋任意の変数名にアンダースコアの同様に、回避 - 。確かにこれは個人的な好みのより多くのですが、 は、なぜあなたは、申請者の名前を除いてどこでもそれらを使用している第二に、あなたはまだ

?かなりの作業が必要です。

あなたは、のために3つのコミュニティごとに1つのユーザー を促し給料のための3つの異なる変数(?)の番号を持つ
  • 、おそらく悪い考えであるあなたは はその後で、すべての3つの数字で動作するようになるでしょうしない限り、同じ時間。また、readln(c_qual_sal)などのステートメントに入力する情報を入力するためのテキストプロンプトも表示されていません。私があなたの意図していることは明らかではなかったので、私は推測しようとしていません。

  • あなたがコミュニティの選択をエコーする方法は、メンテナンス (後でコミュニティを追加したい場合はどうすればよいでしょうか)を作成するだけです。 には、ユーザーが入力したコミュニティ名のいずれかに一致する変数を設定することをお勧めします。

  • コミュニティごとに実行するステートメントは3つあり、それぞれのコミュニティで に複製されています。実際に必要なものはQualifyingSalaryのものだけです - 他は入力されたコミュニティに関係なく実行可能です。

+0

まあ、彼は単に試してみたことがありません。または、彼はhttp://forum.lazarus-ide.org/index.php/topic36060.msg240005/topicseen.html#new –

関連する問題