Pascal help please!

Associate
Joined
11 Nov 2006
Posts
549
Location
Devon
I have a pascal program but i want to introduce an error message or a facility where only a certain input can be entered.

Basically i want the user to only be able to enter posotive numbers and nothing else. What would be the best way to go about this?
 
thing is, we all know this is homework.
so either work it out for yourself, or go ask for help from your tutor.
he gets paid to help you, you know.
he wont mind.
 
... I Really suggest you make sure you fully understand this before you use it, assuming i understood your question properly.
Code:
[B]var[/B]
   TempIn: String;
   TempOut,Err: Integer;

[B]begin [/B]
   Write('Please Input Value:');
   ReadLn(TempIn); 
   VAL(TempIn,TempOut,Err);
   While (Err>0) or (TempOut<1) do begin 
        Write('Sorry, Incorrect Input, Try Again: ');
        ReadLn(TempIn); 
        VAL(TempIn,TempOut,Err);
   end; {Final Value Is Stored to TempOut When Complete }

[B]end.[/B]
 
Last edited:
You could also use an if statement to check if the users input>0, else display your error message.
 
You could also use an if statement to check if the users input>0, else display your error message.


Its better to use a loop, becuase you will need the input to be re entered at some point - and it will need checking again
 
thing is, we all know this is homework.
so either work it out for yourself, or go ask for help from your tutor.
he gets paid to help you, you know.
he wont mind.

Its work but not home work as such. And i prefer peoples views on things here sometimes. A forum can be a place to ask for help and find a better way of doing something.

Thanks to the people who tried to help i've managed to get it working now and works quite nicely. But i'm having a problem getting a procedure to work. Basically the program works, the user enters some figures and then the program estimates some costs and then asks would you like the program to run again if yes then clear all data entered and program starts again in no then close.

Could someone take a look at the code below and see where i'm going wrong?

Thanks in advance

Program PaintEstimator;

Uses crt;

var
customer:string;
length:integer;
width:integer;
windows:integer;
doors:integer;
area:integer;
wall:integer;
woodwork:integer;
ceiling:integer;
doorsarea:integer;
windowsarea:integer;
paint1:real;
paint2:real;
paint3:real;
wallpaper:char;
wallpaper1:integer;
total:real;
total1:real;
total2:real;
total3:real;
subtotal:real;
VATtotal:real;
Grandtotal:real;
Close:Char;

Const
Emulsion = 3.50;
Gloss = 4.00;
Paperroll = 3.00;
VAT = 0.175;

Procedure Reset;
begin
paint1 := 0;
paint2 := 0;
paint3 := 0;
wallpaper1 := 0;
end;

Procedure Data;
begin
clrscr;
writeln ('Please enter the customers name:');
readln (customer);
writeln ('Please enter the length of the room in meters:');
readln (length);
writeln ('Please enter the width of the room in meters:');
readln (width);
writeln ('Please enter the number of doors:');
readln (doors);
writeln ('Please enter the number of windows:');
readln (windows);
writeln ('Would you like wallpaper? (Y/N):');
readln (wallpaper);
end;

Procedure DataProcessing;
begin
doorsarea := doors*2;
windowsarea := windows*2;
area := length*width+doorsarea+windowsarea;
paint1 := area div 8;
paint2 := area div 8;
paint3 := area div 6;
If wallpaper = 'Y' then
wallpaper1 := 4;
total := paint1 * emulsion;
total1 := paint2 * emulsion;
total2 := wallpaper1 * paperroll;
total3 := paint3 * gloss;
subtotal := total+total1+total2+total3;
VATtotal := subtotal*vat;
Grandtotal := subtotal+VATtotal;
end;

Procedure Information;
begin
repeat
writeln('********** Joe Blakes Painting & Decorating Estimator V1.00 **********');
writeln('********** Estimation of Costs for ',customer);
writeln('');
writeln('Materials');
writeln('Ceiling: ', paint1:0:2,' litres @','œ',emulsion:0:2,' per litre ','œ',total:0:2);
writeln('Walls: ', paint2:0:2,' litres @','œ',emulsion:0:2,' per litre ','œ',total1:0:2);
writeln('Rolls of paper: ', wallpaper1,' rolls @','œ',paperroll:0:2,'per roll ','œ',total2:0:2);
writeln('Woodwork: ', paint3:0:2,' litres @','œ',gloss:0:2,' per litre ','œ',total3:0:2);
writeln('Sub Total ','œ',subtotal:0:2);
writeln('VAT 17.5% ','œ',VATtotal:0:2);
writeln('Grand Total ','œ',grandtotal:0:2);
writeln('');
writeln('Would you like to run the estimator again? (Y/N):');
readln(close);
until close ='n';
readln;
end;

begin
reset;
data;
dataprocessing;
information;
end.
 
Becuase you havent told it too?

make a menu procedure and use a case satement should work a treat something like


case choice
1 := procedure1;
2 := etc etc
until choice := 3;
end; < actual end of program
 
Im not doing this one for you unfortunatly , but the problem is you arent repeating the whole thing, dont repeat in procedure, repeat outside where you call the procedure, also - one thing, dont do this :

Code:
var
customer:string;
length:integer;
width:integer;
windows:integer;
doors:integer;
area:integer;
wall:integer;
woodwork:integer;
ceiling:integer;
doorsarea:integer;
windowsarea:integer;
paint1:real;
paint2:real;
paint3:real;
wallpaper:char;
wallpaper1:integer;
total:real;
total1:real;
total2:real;
total3:real;
subtotal:real;
VATtotal:real;
Grandtotal:real;
Close:Char;

Do This

Code:
var
customer:string;
length,width,windows,doors,area,wall,woodwork,ceiling,doorsarea,windowsarea,wallpaper1:integer;
paint1,paint2,paint3,subtotal,vattotal,grandtotal,total,total1,total2,total3:real;
wallpaper,close:char;
 
Back
Top Bottom