Results 1 to 9 of 9

Thread: need pascal programmer

  1. #1
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    Hi,

    I've made this program for my school project. My teacher won't be in for a few days so I can't ask her...

    I've made a program and here is the code:

    Code:
    {Creator - NAME HIDDEN - 7.03.05}
    Program Carpet_Calculator(Input,Output);
    USES Wincrt;
    
    CONST
            Vat_Rate = 0.175;  {This is the vat that has to be added to the total price}
            Adjustment = 0.1;
        
    
    VAR
            length, Width, Area, TotalCost, Discount, TotalCost_Inc_Discount, Vat,
            Total_Cost_plus_VAT,  PricePerMetre, phonenumber                         : Real;
    
            fitting                                                                  : char;
         
    
                                                
         
         
                                  
                                           
    
    
    Begin
    
            Writeln('--------------------------------------------------< by: NAME HIDDEN >---');
            Writeln('                             Carpet Warehouse                           ');
            Writeln('------------------------------------------------------------------------');
    
            Write('Enter the required length (M)?: ');              {Enter the length of the carpet}
            Readln(length);
    
            Write('Enter the required Width? (M)?:  ');             {Enter the Width of the carpet}
            Readln(Width);
    
            Length:= length + Adjustment;                           {Adjustment is 0.1 to take into
                                                                 account sloping walls}                                
            Width:= Width + Adjustment;
    
            Write('Enter the Price Per Metre?:');                   
            Readln(PricePerMetre);
                          
            Area:= Length * Width;
            Writeln('The area is :',Area:5:2); 
            TotalCost:= Area * PricePerMetre;
            writeln('Cost of Carpet is: £',totalcost:5:2);
        {Discount}
    IF      PricePerMetre > 15 THEN
         begin
    
            Discount:= (TotalCost * (10/100));
            Writeln('Discount Amount is £',Discount:5:2);
            TotalCost_Inc_Discount:= TotalCost - Discount;
            totalCost:= TotalCost_Inc_Discount;
            Writeln('Total Cost Including Discount is £',TotalCost:5:2);     
    
         end;
                            
         
        {vat}
            VAT:= TotalCost * VAT_Rate;
            Writeln('Vat Amount is: £',Vat:5:2);
            Total_Cost_plus_VAT:= TotalCost + VAT;
            Writeln('Total Cost Including VAT: £', Total_Cost_plus_VAT:5:2);
            writeln;
            write('Would you like your carpet fitted? (Y or N): ');
            readln(fitting);
    If      fitting = 'Y' then 
    begin
    
            totalCost:=Total_Cost_plus_VAT +30;
            writeln('An Extra £30 will be added: £ ',totalcost:5:2);
    
    end
    
    else
    
    If     fitting = 'y' then
    begin
           totalCost:=Total_Cost_plus_VAT +30;
           writeln('An Extra £30 will be added. The final price is: £',totalcost:5:2);
    
    end   
    
    
    else
    
           writeln('No Fitting required...');
    
    
    writeln('Enter Customer Phone Number:');
    readln(phonenumber);
    
    end.
    This is what i have to do:

    1. The length, width and price per metre values must not accept zero.

    2. the range of price per metre values allowed, should not be zero and should not exceed £50.

    3. Include some code in the program to allow the entry of the customer’s telephone number, ensure that the telephone number only contains numbers, no alphabetic or other characters allowed.


    I've added the phone number option (at teh bottom of the code), but I have no idea how to make the program not accept 0 and for the price per metre not exceed £50

    If someone can help, thanx thanx thanx!!!!
    Last edited by 99shassan; 06-15-2005 at 09:26 PM.
    Changed SPAN settings in sig a YEAR after it was removed

  2. Software & Hardware   -   #2
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    how about adding an if statement to make sure what has been entered is greating then zero. if it's not send it back to reinput a new value. you will need to place it all inside a loop where you can only break out if the value is greater then zero.

  3. Software & Hardware   -   #3
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    cool

    I'll see if I can do that
    Changed SPAN settings in sig a YEAR after it was removed

  4. Software & Hardware   -   #4
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    Here is the update:

    Code:
    {Creator - NAME HIDDEN - 7.03.05}
    Program Carpet_Calculator(Input,Output);
    USES Wincrt;
    
    CONST
            Vat_Rate = 0.175;  {This is the vat that has to be added to the total price}
            Adjustment = 0.1;
        
    
    VAR
            length, Width, Area, TotalCost, Discount, TotalCost_Inc_Discount, Vat,
            Total_Cost_plus_VAT,  PricePerMetre, phonenumber                         : Real;
    
            fitting                                                                  : char;
         
         
                                  
                                           
    
    
    Begin
    
            Writeln('--------------------------------------------------< by: NAME HIDDEN >---');
            Writeln('                             Carpet Warehouse                           ');
            Writeln('------------------------------------------------------------------------');
    
          REPEAT                                                    {Loop until requirement met}
            Write('Enter the required length (M)?: ');              {Enter the length of the carpet}
            Readln(length);
            IF length=0 THEN                                        {If statement begins. If length=0 then begin next code}
    
    Begin
            Writeln('Length Cannot be 0. Please try again');        {If length was 0 then it will display this comment and loop
                                                                     back to Accept Length}
    End;
          UNTIL length>0 ;                                          {This is requirement of Loop. When met, the loop is broken
                                                                     and next code can begin}
    
    Begin   
          REPEAT                                                    {Loop until requirement met}
            Write('Enter the required Width? (M)?:  ');             {Enter the Width of the carpet}
            Readln(Width);
            IF width=0 THEN                                         {If statement begins. If width=0 then begin next code}
    
    Begin
            Writeln('Width cannot be 0. Please Try again');         {If width was 0 then it will display this comment and loop
                                                                     back to Accept Width}
    End;
          UNTIL width>0 ;                                           {This is requirement of Loop. When met, the loop is broken
                                                                     and the next code can begin}
    
    Begin
            Length:= length + Adjustment;                           {Adjustment is 0.1 to take into
                                                                     account sloping walls}                                
            Width:= Width + Adjustment;
    END;
          REPEAT                                                    {Loop until requirement met}
            Write('Enter the Price Per Metre?:');                   
            Readln(PricePerMetre);
            IF pricepermetre=0 THEN                                 {If price per metre is 0 then begin next perform next code}
    
    Begin
            Writeln('Cannot Be £0. Please try again...');           {If price per metre was 0 then write this comment and loop
                                                                     back to Accept price per metre}
    End;      
          Until PricePerMetre>0 ;                                   {If price per metre is higher than 0 then requirement is met
                                                                     and loop is broken and the next code can begin}
          
    Begin 
            Area:= Length * Width;                                  {To work out the area}
            Writeln('The area is :',Area:5:2); 
            TotalCost:= Area * PricePerMetre;                       {To work out the cost of the carpet for the
                                                                     specified measurements}
            writeln('Cost of Carpet is: £',totalcost:5:2);
    
        {Discount}
    IF      PricePerMetre > 15 THEN                                 {IF Statement starts here}
                                                                    {If the Price per metre is higher than 15,
                              	   	                         then it will perform code below "begin"}
    Begin
    
            Discount:= (TotalCost * (10/100));                      {Work out 10% of the total cost}
            Writeln('Discount Amount is £',Discount:5:2);
            TotalCost_Inc_Discount:= TotalCost - Discount;          {total cost - 10% of total cost}
            totalCost:= TotalCost_Inc_Discount;
            Writeln('Total Cost Including Discount is £',TotalCost:5:2);     
    
    end;                                                            {IF Statement Ends}
                            
         
        {VAT}                                                      
            VAT:= TotalCost * VAT_Rate;                             {to work out VAT of total cost, VAT is
     					                         0.175}
            Writeln('Vat Amount is: £',Vat:5:2);
            Total_Cost_plus_VAT:= TotalCost + VAT;                  {total cost + VAT will equal
                                                                     total_cost_plus_VAT} 
            Writeln('Total Cost Including VAT: £', Total_Cost_plus_VAT:5:2);
            writeln;
    
            write('Would you like your carpet fitted? (Y or N): ');
            readln(fitting);
    If      fitting = 'Y' then                                      {If statement starts here}
    
    Begin
    
            totalCost:=Total_Cost_plus_VAT +30;
            writeln('An Extra £30 will be added: £ ',totalcost:5:2);
                                                                    
    end
    
    else
    
    If      fitting = 'y' then                                      {If statement starts here}
    
    begin
            totalCost:=Total_Cost_plus_VAT +30;
            writeln('An Extra £30 will be added. The final price is: £',totalcost:5:2);
    
    end                                                        
    
    else
            writeln('No Fitting required...');
    
    BEGIN
    
            writeln('Enter Customer Phone Number:');
            readln(phonenumber);
    
    end;
    end;
    end;
    end.
    I have to make it work so taht the price per metre will not accept 0 or >50

    I have got it to work with anything above 0. But not 50. How do I add that feature along with the current no 0 policy? Also, why do I have to have so many
    "end;" on the last part of the code? It doesn't run otherwise, it keeps giving an "error 85 code: ; expected". thanks
    Changed SPAN settings in sig a YEAR after it was removed

  5. Software & Hardware   -   #5
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    you need to change IF length=0 THEN to ask if the length is > 0 or < 50

    http://www.functionx.com/objectpascal/Lesson16.htm

  6. Software & Hardware   -   #6
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787
    Quote Originally Posted by 4play
    you need to change IF length=0 THEN to ask if the length is > 0 or < 50

    http://www.functionx.com/objectpascal/Lesson16.htm
    huh? I changed length to:

    Code:
    REPEAT                                                    {Loop until requirement met}
            Write('Enter the required length (M)?: ');              {Enter the length of the carpet}
            Readln(length);
            IF length=0 THEN                                        {If statement begins. If length=0 then begin next code}
    
    Begin
            Writeln('Length Cannot be 0. Please try again');        {If length was 0 then it will display this comment and loop
                                                                     back to Accept Length}
    End;
          UNTIL length>0 ;                                          {This is requirement of Loop. When met, the loop is broken
                                                                     and next code can begin}
    The reason I put Until length>0 there because otherwise it wouldn't put please try again message when run. I'm trying to make it so that the price per metre can't be 0 or above 50. And the reason I put

    Code:
       Until PricePerMetre>0 ;
    where this is in the program is also because I wanted to display that error if 0 is typed. I don't know waht to do. will that site help in thsi case?
    Changed SPAN settings in sig a YEAR after it was removed

  7. Software & Hardware   -   #7
    4play's Avatar knob jockey
    Join Date
    Jan 2003
    Location
    London
    Age
    41
    Posts
    3,824
    try using

    if (length=0) or (length > 50) then

    edit: and change the line about not being able to use zero to say you must keep it under 50 as well.
    Last edited by 4play; 06-16-2005 at 12:42 AM.

  8. Software & Hardware   -   #8
    Barbarossa's Avatar mostly harmless
    Join Date
    Jun 2002
    Location
    Over here!
    Posts
    15,180
    Quote Originally Posted by 99shassan
    I have got it to work with anything above 0. But not 50. How do I add that feature along with the current no 0 policy? Also, why do I have to have so many
    "end;" on the last part of the code? It doesn't run otherwise, it keeps giving an "error 85 code: ; expected". thanks
    Something like this:

    Code:
    REPEAT                                                    
       Write('Enter the Price Per Metre?:');                   
       Readln(PricePerMetre);
    
       IF pricepermetre=0 THEN
       BEGIN                                 
          Writeln('Cannot Be £0. Please try again...');
       END;
       IF pricepermetre>50 THEN
       BEGIN                                 
          Writeln('Cannot Be Greater Than £50. Please try again...');
       END;
    
    UNTIL (PricePerMetre>0) AND (PricePerMetre<=50);
    You might find it helps to determine how many END's you need at the bottom, if you indent the nested BEGIN..END clauses in the code as I have done above.

    It looks to me like you've got a few extra BEGINs in your code, I think the ones after the UNTILs you don't need..

  9. Software & Hardware   -   #9
    99shassan's Avatar Poster BT Rep: +1
    Join Date
    Jul 2003
    Posts
    787

    Smile

    tanks for the help guys! much appreciated
    Changed SPAN settings in sig a YEAR after it was removed

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •