Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi math Code challenge

Status
Not open for further replies.

8622870073

Programmer
Nov 3, 2010
2
BZ
How to add the following numbers from user input and find the average of them, each number will be in a seperate edit box and you are suppose to get the average of the numbers inputed example 100+200+200+200+200 is equals to 900 then i will take 900 and divide it by the amount of numbers, which in this case is 5. from the result of that there will be 15% removed to get the final answer.

100+200+200+200+200=900

900/5=180

180*15%= 27
 
in tbutton1 i placed the code

var
numbers : array[1..5] of Double;
aveVal, meanVal : Double;

begin
// Set up the array of 5 floating point numbers
numbers[1] := 1.0;
numbers[2] := 2.5;
numbers[3] := 3.0;
numbers[4] := 4.5;
numbers[5] := 25.0;

// Calculate the average of these numbers
aveVal := (numbers[1] + numbers[2] + numbers[3] +
numbers[4] + numbers[5]) / 5;

// Calculate the mean of these numbers
meanVal := Mean(numbers);

// Show these values
Edit6.text :=('Average = '+FloatToStr(aveVal));
end;

but i want the input from edit1-5 and show result in edit6 the average for now.

insted of numbers for the arrays have them get it from user input on the editboxes.
 
If I help you do I get your grade, too?

It is not possible for anyone to acknowledge truth when their salary depends on them not doing it.
 
It looks to me like you've done all of the mathematics part.

Reverse the logic of your last line:
Code:
 Edit6.text :=('Average = '+FloatToStr(aveVal));

to get something like:
Code:
 numbers[1] := StrToFloat(Edit1.Text);

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top