Help on Pascal Program: Pressure - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Help on Pascal Program: Pressure

rodneybunkleyrodneybunkley Posts: 5Member
Hi, I had a question about this program. I'm suppose to put the pressures in intervals. But everytime I read in multiple values, it outputs only the last value entered. I'm not allowed to use multiple variables for pressure, I only can use one and would have to do a loop to read in the values one by one. Can anyone tell me how I do that?


PROGRAM PRESSURES (INPUT, OUTPUT, DATA7, OUT7);

VAR N, PRESSURE, HIGH, LOW, TOTAL, ICOUNT, AVERAGE, INTERVAL,
PCOUNT: INTEGER;
DATA7, OUT7: TEXT;

(********************************************************************)

PROCEDURE ProcessPressures(VAR HIGH, PRESSURE, LOW, TOTAL, AVERAGE,
PCOUNT: INTEGER);
BEGIN
TOTAL:= 0;
PCOUNT:= 0;
HIGH:= -MAXINT;
LOW:= MAXINT;
WRITELN('ENTER PRESSURES:');
READ(PRESSURE);
WHILE NOT EOF DO
BEGIN
PCOUNT:= PCOUNT + 1;
TOTAL:= TOTAL + PCOUNT;
IF EOLN
THEN READLN;
IF NOT EOF
THEN READ(PRESSURE);
IF PRESSURE > HIGH
THEN HIGH:= PRESSURE;
IF PRESSURE < LOW
THEN LOW:= PRESSURE;


END;
AVERAGE:= TOTAL DIV PCOUNT;
END;

(*********************************************************************)

PROCEDURE PrintsSummaryResults(VAR INTERVAL, PRESSURE, HIGH, LOW,
AVERAGE: INTEGER);
BEGIN
WRITELN('NUMBER OF INTERVALS TO MONITOR: ', N);
WRITELN('******************************************************');
WRITELN('PROCESS 1 PRESSURE: ', PRESSURE);
WRITELN('PROCESS 2 PRESSURE: ', PRESSURE);
WRITELN('PROCESS 3 PRESSURE: ', PRESSURE);
WRITELN('PROCESS 4 PRESSURE: ', PRESSURE);
WRITELN('PROCESS 5 PRESSURE: ', PRESSURE);
WRITELN('PROCESS 6 PRESSURE: ', PRESSURE);
IF HIGH > 5000
THEN WRITELN('DANGER! OVERPRESSURE OF ', HIGH);
IF LOW < 14
THEN WRITELN('DANGER! VACUUM OF ', LOW);

WRITELN('HIGH PRESSURE IS ', HIGH);
WRITELN('LOW PRESSURE IS ', LOW);
WRITELN('AVERAGE PRESSURE IS ', AVERAGE);
WRITELN('******************************************************');
END;
(**********************************************************************)

BEGIN
RESET(DATA7);
REWRITE(OUT7);
WRITE('ENTER NUMBER OF INTERVALS:');
READ(N);
ICOUNT:= 0;
WHILE NOT EOF DO
BEGIN
ProcessPressures(HIGH, PRESSURE, LOW, AVERAGE, TOTAL, PCOUNT);
PrintsSummaryResults(INTERVAL, PRESSURE, HIGH, LOW, AVERAGE);
ICOUNT:= ICOUNT + 1
END;
END.

Comments

  • ActorActor Posts: 438Member
    [code]
    program Pressures ;

    CONST
    MAXREAL = 1.0E37 ;

    type
    pressuretype = array [1 .. 1000] of real ;


    Procedure GetPressures (var n : integer ; var pressure : pressuretype) ;

    begin
    n := 1 ;

    writeln ('ENTER A NEGATIVE PRESSURE TO TERMINATE DATA INPUT.') ;
    writeln ;

    while TRUE do begin
    write ('ENTER PRESSURE #', n:0, ' ') ;
    readln (pressure[n]) ;
    if pressure[n] < 0.0 then begin
    n := n - 1 ;
    exit
    end ;
    n := n + 1
    end
    end ;


    procedure ProcessPressures (n : integer ;
    pressure : pressuretype ;
    var
    high, low, average : real) ;

    var
    total : real ;
    count : integer ;

    begin
    total := 0.0 ;
    count := 0 ;
    high := pressure[1] ;
    low := pressure[1] ;

    for count := 1 to n do begin
    total := total + pressure[count] ;
    if pressure[count] > high then
    high := pressure[count] ;
    if pressure[count] < low then
    low := pressure[count]
    end ;

    average := total / count
    end ;


    procedure PrintSummaryResults (n : integer ;
    pressure : pressuretype ;
    high, low, average : real) ;

    var
    i : integer ;

    begin
    writeln('NUMBER OF INTERVALS TO MONITOR: ', n) ;
    writeln('**********************************') ;

    for i := 1 to n do
    writeln('PROCESS ', i:0, ' PRESSURE: ', pressure[i]:10:3);
    writeln ;
    if high > 5000.0 then
    writeln('DANGER! OVERPRESSURE OF ', high:0:3) ;
    if low < 14.0 then
    writeln('DANGER! VACUUM OF ', low:0:3) ;

    writeln('HIGH PRESSURE IS ', high:0:3) ;
    writeln('LOW PRESSURE IS ', low:0:3) ;
    writeln('AVERAGE PRESSURE IS ', average:0:3) ;
    writeln('************************************')
    end;


    var
    n : integer ;
    pressure : pressuretype ;
    high,
    low,
    average : real ;

    begin
    GetPressures (n, pressure) ;
    ProcessPressures (n, pressure, high, low, average);
    PrintSummaryResults (n, pressure, high, low, average);
    end.
    [/code]
Sign In or Register to comment.