PDA

View Full Version : need pascal programmer



99shassan
06-15-2005, 09:25 PM
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:


{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!!!!

4play
06-15-2005, 09:34 PM
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.

99shassan
06-15-2005, 09:39 PM
cool

I'll see if I can do that

99shassan
06-15-2005, 11:36 PM
Here is the update:



{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

4play
06-15-2005, 11:45 PM
you need to change IF length=0 THEN to ask if the length is > 0 or < 50

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

99shassan
06-16-2005, 12:33 AM
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:


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


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?

4play
06-16-2005, 12:40 AM
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.

Barbarossa
06-16-2005, 09:12 AM
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:



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..

99shassan
06-17-2005, 12:24 AM
tanks for the help guys! much appreciated :):)