 # using arraysRSS

## 2 replies

Last post Feb 05, 2019 06:52 PM by Nova Jacob

• ### using arrays

Feb 03, 2019 12:28 PM|rowlandsfc|LINK

im first year college studying coding as part of my course and i have to write up the game hammurabi, im trying to use arrays to store data baasedon results of calculations from data entered by the user and implenebted on a click of a button.

```            int[] starved = new int;

starved = died;
starved = died;
starved = died;
starved = died;
starved = died;
starved = died;
starved = died;
starved = died;
starved = died;
starved = died;

if (year == 11)
{
int average, sum = 0;
for (int i = 0; i < 10; i++)
{

sum = sum + starved[i];

}
average = sum / 10;

label11.Text = average + " on average died peer year";
}
```

died the is the amount of people who have died for what ever reason in that specific year, what imtrying to do is run the game for 10 years and each year save the number of people died and then at the end of year 10/start of year 11 calculate the avergae amount of people who died and display it in a label

not currently working atm so any advice would be appreciated

• ### Re: using arrays

Feb 04, 2019 08:21 AM|Yuki Tao|LINK

Hi rowlandsfc,

According to your descriptions,I make a demo,you could refer to it:

``` public static void Main()
{

int[] starved= new int;
int average, sum = 0;
for (int i = 0; i < 50; i++)
{
Console.WriteLine("Please enter the number:");
starved[i] =Convert.ToInt32(Console.ReadLine());
sum = sum + starved[i];
if (i % 10 == 0&&i>0)//when year11 or year21 ...
{
average = sum / i;
Console.WriteLine("This is year {0},average is {1}",i+1,average);
}

}

Console.ReadKey();

}```

How it works: Best Regards.

Yuki Tao

Please remember to "Mark as Answer" if suggestion helps.
• ### Re: using arrays

Feb 05, 2019 06:52 PM|Nova Jacob|LINK

Since you are doing division like below

`average = sum / 10;`

The average variable should be double or float data type.

The calculation should be

`average = (double) sum / 10;`