Reputation: 13
I am working on a text-based game, and I want to print the results in the end. However, at the moment it only prints the latest input data and not the 5 loops in the array.
This is my array
int[] turnarr = new int[5];
turnarr[x] = turn;
for (int i = 0; i < turnarr.Length; i++)
Console.WriteLine(turnarr[i] + "\t" );
Upvotes: 1
Views: 4908
Reputation: 13196
I took a look at your pastebin and tracked the issue down I believe:
The following line:
Console.WriteLine(turnarr[i] + "\t" + windarr[i] + " ms \t" + apmeterarr[x] + "m\t\t" + lenghtarr[x] + " meter\t\t");
you are using i for 2 spots, and x for the other 2 for your index variable...
Change
apmeterarr[x]
and
lenghtarr[x]
To
apmeterarr[i]
and
lenghtarr[i]
Upvotes: 0
Reputation: 700152
It's hard to be certain, as I only see part of the code, but I suspect that you are recreating the turnarr
array in each turn, which would make every entry except the last one zero.
Upvotes: 2
Reputation: 13947
If turn
is your last turn value, and x
is 4, you will see four zeroes on their own lines and then the value of turn
because you are only assigning to the x
th index of turnarr
Upvotes: 1
Reputation: 13641
If the value of x
never changes then you're only writing to a single item in the array, and thus overwriting it every time with the latest value of turn
.
Upvotes: 1