Dear Sir,

Could you tell me what is wrong of my program?

The question is: write a progrm that totals up a list of exactly 100 numbers and outputs that total to the screen, also show the average of the 100 numbers.

My program:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
        total, number, count: integer;
        average: real;

begin
        total:=0;
        for count:=1 to 100 do
           begin
              readln(number);
              total:=total+number;
           end;
        writeln(total);
        average:=total/100;
        writeln(average:6:2);
end.

Dear Sir,

Could you tell me what is wrong of my program?

The question is: write a progrm that totals up a list of exactly 100 numbers and outputs that total to the screen, also show the average of the 100 numbers.

My program:

program Project2;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
        total, number, count: integer;
        average: real;

begin
        total:=0;
        for count:=1 to 100 do
           begin
              readln(number);
              total:=total+number;
           end;
        writeln(total);
        average:=total/100;
        writeln(average:6:2);
end.

You may need to store average to a double (float), or maybe a variant.

Not sure which pascal you are using.

Hi turbomen.
Your program is working well....where is the problem?
If you want to get the average result as decimals then
write here:
Write('The average is :',average:6:0);
got it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.