Hi everyone,

I am a new in Delphi,and trying to learn it. I am using Delphi 2005. I will like to find out a code for creating a form that will calculate the average of three different parameters and display the message box with the calculated averages.

first let's see the algorithm
(a+b+c)/3
i made it in console application

program average;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var a,b,c,e:real;
begin
   write('first number: ':20);
   readln(a);
   write('second number: ':20);
   readln(b);
   write('third number: ':20);
   readln(c);
   e:=(a+b+c)/3;
   write('the average : ':20,e:0:2);
   readln;
end.
{created by FlamingClaw 2009}

windows application same as above
place three editboxes as edit1,edit2,edit3
and a button as button1 onto the form(caption set to Average)
double click on the button to open the code
editor

procedure TForm1.Button1Click(Sender: TObject);
var sedit1,sedit2,sedit3,s :string;
    num1,num2,num3:integer;
    num4:real;
    code1,code2,code3:integer;
begin
  sedit1:=edit1.Text;
  sedit2:=edit2.Text;
  sedit3:=edit3.Text;
  val(sedit1,num1,code1);//converts string to number
  val(sedit2,num2,code2);//codes are contains the
  val(sedit3,num3,code3);//error codes
  if (code1<>0) or (code2<>0) or (code3<>0) then
  showmessage('Wrong data entered.')
  else begin
    num4:=(num1+num2+num3)/3;
    str(num4:0:3,s); //converts number to string
    showmessage(s);
  end;
end;

write one number to each editboxes and press the button.
it is working fine,good luck.

This question has already been answered. Start a new discussion instead.