Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help on Pascal Program: Pressure Posted by rodneybunkley on 7 Apr 2010 at 1:19 PM
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.
Report
Re: Help on Pascal Program: Pressure Posted by Actor on 8 Apr 2010 at 8:31 PM
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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.