Re: need pascal programmer
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.
Re: need pascal programmer
cool
I'll see if I can do that
Re: need pascal programmer
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
Re: need pascal programmer
you need to change IF length=0 THEN to ask if the length is > 0 or < 50
http://www.functionx.com/objectpascal/Lesson16.htm
Re: need pascal programmer
Quote:
Originally Posted by 4play
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?
Re: need pascal programmer
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.
Re: need pascal programmer
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..
Re: need pascal programmer
tanks for the help guys! much appreciated :):)