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
Delphi Fun Posted by la65cop on 21 Feb 2009 at 3:46 PM
Alright, I'm trying to write a program that finds the highest, lowest, and average number of a set of undetermined data. Also, the program needs to shut off when you enter a negative number.


This is what I have so far, the only thing working is the highest number.... please help thanks so much



program TestData;

uses
Forms;

{$R *.RES}




var
outfile:textfile;
number,hi,lo,A:integer;
name:string;


Procedure Start;

begin

assignFile(outfile,'TestData.out');
rewrite(outfile);
write('What is your name?: ');
readln(name);
writeln(outfile,'This program was run by: ',name);
writeln(outfile);
repeat
writeln('Enter your number: ',number);
readln(number);


A:=number+number;
if hi<number then hi:=number;
if (number<hi) and (number>0) and not (number=0) then lo:=number;


until number<0;
writeln(outfile,'The Highest number is :',hi);
writeln(outfile,'The lowest number is : ',lo);
writeln(outfile,'The average is: ',A);

end;


Procedure Done;
begin
writeln(outfile,'This program was created by me');
closefile(outfile);

end;

begin
Start;
Done;
end.

Report
Re: Delphi Fun Posted by Actor on 21 Feb 2009 at 7:16 PM
 
program TestData;
uses
  Forms;

{$R *.RES}

var
    outfile:textfile;
    number,hi,lo,A:integer;
    name:string;
    Count : Integer ;

        Procedure Start;
        begin
            {
            initialize
            }
            A     := 0 ;
            hi    := 0 ;
            lo    := 32767 ;
            Count := 0 ;

            assignFile(outfile,'TestData.out');
            rewrite(outfile);
            write('What is your name?: ');
            readln(name);
            writeln(outfile,'This program was run by: ',name);
            writeln(outfile);
            repeat
                writeln('Enter your number: ',number);
                readln(number);
                
                
                if number < 0 then
                    break ;
                A := A + number;
                if number > hi then
                    hi := number;
                if number < lo then
                    lo := number ;
                Count := Count + 1
                
            until number<0;
            
            writeln(outfile,'The Highest number is :',hi);
            writeln(outfile,'The lowest number is : ',lo);
            writeln(outfile,'The average is: ',A DIV Count);  { truncates }
        end;


        Procedure Done;
        begin
            writeln(outfile,'This program was created by me');
            closefile(outfile);
        end;

begin
    Start;
    Done;
end.

Report
Re: Delphi Fun Posted by la65cop on 21 Feb 2009 at 7:44 PM
you are the mannn thank you so much, this makes much more sense



 

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.