折扣计算器

时间:2014-03-15 03:58:39

标签: calculator pascal

美好的一天,我是编程的新手,我正在尝试用pascal编写的折扣计算器。可悲的是,我遇到了一些问题。我发布了我的代码,我希望你们都能指出我哪里出错了。

program Discount_Calulator;
    {Name: Yohan Henry}
    {Date: 28.02.2014}
    {Purpose:To accept the customer name and total payment then calculate the discount given to the customer then finally print the customer's name, customer's total payment, customer's discount, customer's after discount price and total discount}

    Var
    Total_discount: real;
    [Y]: integer;                            {Here I listed all my variables I needed to make the program}
    After_discount Array [1.20]: real;
    Establishment Array [1.20]: real;
    Total_payment Array [1.20]: real;
    Discount Array [1.20]: real;

    Begin
    start
    clscr;
    Total Discount := 0;
    FOR Y := 1 to 20 DO
    After_discount [Y] := 0;                     {Here Initialized my variables to make it easier to run}
    Total_payment [Y] := 0;
    Discount [y] ;= 0;
    END FOR

    FOR [Y] := 1 to 20 DO
    writeln 'Enter Customer Name';
    readln 'Establishment [Y]';
    writeln 'Enter the Customer's Total Payment';
    reanln 'Total_payment [Y]';
    END FOR

    FOR [Y] := 1 to 20 DO
    IF Total_payment [Y] >= 15000 THEN
    Discount [Y] := Total_payment [Y] * 0.10;
    END IF

    IF Total_payment [Y] >= 12500 AND
    Total_payment [Y] < 15000 THEN
    Discount [Y] := Total_payment [Y] * 0.05
    END IF

    IF Total_payment  [Y] > 10500 AND
    Total_payment [Y] < 12500 THEN
    Discount [Y] := Total_payment [Y] * 0.02
    END IF

    After_discount [Y] := Total_payment [Y] - Discount [Y]
    Total_discount [Y] := Total_discount [Y] + Discount [Y]
    END FOR [Y] := 1;

    WHILE [Y] <= 20 DO
    WHILE LOOP TO PRINT
    writeln 'The Customer Name is Establishment [Y]'
    writeln  'The Total_payment of the Customer is $x', Total_payment [Y]'
    writeln  'The Customer Discount is $x', Discount [Y]'
    writeln  'The Customer Price after Discount is $x', After_discount [Y]'
    Y := Y + 1
    writeln  'The Total Overall Discount is $x', Total_discount [Y]
    END.  

1 个答案:

答案 0 :(得分:-1)

我发现了一个:你说的地方&#34; {这里初始化我的变量以便更容易运行}&#34;,Discount [y] ;= 0;必须是Discount [y] := 0;。我可以想象这种语法错误的错误信息并不清楚。

然后我发现了一个&#34; reanln&#34; (&#34; readln&#34 ;?)。如果这是你尝试翻译的原始代码,那么编译器可能会抱怨。