playMaker

Author Topic: Integer Array Average  (Read 893 times)

MichaelPatriot21

  • Playmaker Newbie
  • *
  • Posts: 23
Integer Array Average
« on: May 12, 2019, 08:46:00 PM »
If I make an array of intergers, how would I go about getting an average and storing it in a global variable? I'm making a grand strategy game, each country has a reputation with your organization. So I want to make an array of all the North American countries' relationship with you and display the average relationship you have with North America.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Integer Array Average
« Reply #1 on: May 13, 2019, 04:54:52 PM »
Hi.
You can loop thru the array with 'Array get next' and add all the int's into a variable (call it 'Total' for example)

Then get the length of the array with 'Array Length'.

Then use a float operator and divide the Total by the array length. and store in a float variable.

Then if you wish you can use 'Convert Float To Int' and you can select the 'Rounding' you wish.

MichaelPatriot21

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Integer Array Average
« Reply #2 on: May 13, 2019, 05:17:36 PM »
Thank you, this is what I was looking for.